Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77812677
BasicImageStats.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 16, 13:32
Size
1 KB
Mime Type
text/x-java
Expires
Sun, Aug 18, 13:32 (2 d)
Engine
blob
Format
Raw Data
Handle
19925274
Attached To
R6269 BIOP Run Macro
BasicImageStats.java
View Options
import
mpicbg.imglib.cursor.Cursor
;
import
mpicbg.imglib.image.Image
;
import
mpicbg.imglib.type.numeric.RealType
;
public
class
BasicImageStats
{
/**
* Calculates the mean of an image.
*
* @param img The image to calculate the mean of
* @return The mean of the image passed
*/
public
static
<
T
extends
RealType
<
T
>>
double
getImageMean
(
Image
<
T
>
img
)
{
double
sum
=
0
;
Cursor
<
T
>
cursor
=
img
.
createCursor
();
while
(
cursor
.
hasNext
())
{
cursor
.
fwd
();
T
type
=
cursor
.
getType
();
sum
+=
type
.
getRealDouble
();
}
cursor
.
close
();
return
sum
/
img
.
getNumPixels
();
}
/**
* Calculates the min of an image.
*
* @param img The image to calculate the min of
* @return The min of the image passed
*/
public
static
<
T
extends
RealType
<
T
>>
double
getImageMin
(
Image
<
T
>
img
)
{
double
min
=
img
.
createType
().
getMaxValue
();
Cursor
<
T
>
cursor
=
img
.
createCursor
();
while
(
cursor
.
hasNext
())
{
cursor
.
fwd
();
T
type
=
cursor
.
getType
();
double
currValue
=
type
.
getRealDouble
();
if
(
currValue
<
min
)
min
=
currValue
;
}
cursor
.
close
();
return
min
;
}
/**
* Calculates the max of an image.
*
* @param img The image to calculate the max of
* @return The max of the image passed
*/
public
static
<
T
extends
RealType
<
T
>>
double
getImageMax
(
Image
<
T
>
img
)
{
double
max
=
img
.
createType
().
getMinValue
();
Cursor
<
T
>
cursor
=
img
.
createCursor
();
while
(
cursor
.
hasNext
())
{
cursor
.
fwd
();
T
type
=
cursor
.
getType
();
double
currValue
=
type
.
getRealDouble
();
if
(
currValue
>
max
)
max
=
currValue
;
}
cursor
.
close
();
return
max
;
}
}
Event Timeline
Log In to Comment