FAQ: Understanding Memory and Filters (Spatial): Mean: Difference between pages

From MIPAV
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
MIPAV>Olgavovk
mNo edit summary
 
Line 1: Line 1:
When MIPAV performs a function, such as visualizing an image file, it uses RAM on your computer. When you run MIPAV for the first time you must specify the maximum amount of memory (it calls the maximum heap size in the dialog box) that you would like to allocate for MIPAV, so it can take the full advantage of the memory resources available in your machine. The default value is 1000 MB.  The amount of memory you can allocate to MIPAV is limited by how much RAM is installed on your system.
This algorithm provides a simple way of reducing noise either in an entire image or in a delineated VOI in the image where


== User permissions ==
;; Mean = sum of all pixels in the kernel / total number of pixels in the kernel
MIPAV’s memory allocation is a program-level feature and it affects all users of a given MIPAV installation. You can only change the amount of allocated memory, if you are running MIPAV using an administrative account.


== Memory limitations ==
This is one method of low-pass filtering, which is sometimes referred to as ''neighborhood averaging''.


{| class="wikitable" style="text-align: center; color: black;"
=== Background ===
|-
|  '''OS'''
| '''Max memory
|-
|Windows 32
|1.3 GB
|-
|Windows 64
|196 TB
|-
|Mac OS
|196 TB
|-
|Linux 32
|4 GB
|-
|Linux 64
|196 TB
|}


'''Comment:''' These memory allocations are limited by how much RAM is installed on your computer.
In applying this algorithm, MIPAV first defines a region, either in the whole image or in the delineated VOI, over which it replaces a target pixel value with the average value over the kernel of pixels in which the target pixel is at the center. That is, for the target pixel:


== How can I allocate (more) memory for MIPAV? ==
<math>
mean = \frac {1} {s} \sum_{i=1}^{i=s} I_i k_i
</math>


=== When you are installing MIPAV ===
where ''k ''''<nowiki>= kernel,</nowiki>'''' s'' = kernel size, and ''I'' = image.


[[File:JvmMemoryLimit.png|500px|thumb|right|Installing MIPAV: the JVM Memory Limit tab]]
For ''slice averaging ''(Figure 1] and (Figure2), the kernels are odd-length squares (for example, 3 x 3). The processing time increases with the square of the kernel length. For'' volume averaging ''( Figure 2), the kernels are odd-length cubes (such as 5 x 5 x 5), and the processing time increases with the cube of the kernel length. Refer to Figure 2 for examples of slice and volume averaging.


Starting [http://mipav.cit.nih.gov/download.php version 5.4.2] the easiest way to allocate memory in MIPAV is to do it when you are installing MIPAV. You can define the memory value in the JVM Memory Limit pane. The default value is set to 1000 MB. In the Pre-Installation summary pane, you can review memory settings, and then return back to the JVM Memory Limit pane and adjust them, if needed.
Note that the term ''average'' does not always represent the mean. If fact, there are three types of average: the commonly used mean, the median, and the infrequently used mode. The ''mean'' is defined as the sum of the values in a group divided by the number of values in the group. The ''median'' value is the value that has the same number of values greater and less than it. The ''mode'' is the value with the greatest number of occurrences.


In case you figured out later that you need [[#HowMuchMemory | more memory]], you can still make adjustments using the Check java-runtime Memory Allocation dialog box [[#ChangeJava |options]]. See instructions provided for different operational systems below.
If part of the neighborhood kernel falls outside the image when the pixel is on or near the boundary, MIPAV only uses that portion of the kernel inside the image.


<div> </div>


<div id="WindowsMemory"></div>
{| width="90%" border="1" frame="hsides" frame="hsides"
=== Windows users: adjusting memory settings ===
|-
<div id="ChangeJava"></div>
| width="9%" valign="top" |
<ol>
[[Image:exampleicon.gif]]
<li>Login to your computer under the administrative account, or under the user account who installed MIPAV. </li>
| width="81%" bgcolor="#B0E0E6" | '''Example:''' Consider the upper right corner pixel in a 2D image if a 3 x 3 kernel is used. In this case, when the algorithm is applied, MIPAV uses only the target pixel and its lower, left, and diagonal left lower neighbors. It then divides the sum of these four pixels by 4.
|}


<li>Select Help &raquo; Memory allocation in the Main MIPAV window. The Check java-runtime Memory Allocation dialog box opens.</li>
<br />


<li>In the dialog box, change the maximum heap size number so it reflects the maximum amount of memory you might need. Note that for Windows 32, there is a 1.3 GB limit for memory allocation.</li>
If you select the New image option, MIPAV places the resulting image in a new image window. If you select the Replace image option, MIPAV returns the changed picture to the same image window. If you delineate a VOI on the image and select VOI regions, then MIPAV replaces the original value of a pixel inside the VOI with the mean value of the kernel that contains the pixel at its center. The pixel values outside the VOI remain unchanged.


<div>


[[File:MemoryAllocation.png|429px|thumb|center| The Change java-runtime Memory Allocation dialog box]]
{| border="1" cellpadding="5"
|+ <div>'''Figure 1. Slice averaging''' </div> In slice averaging, MIPAV defines a region and replaces the target pixel value with the average value over the kernel of pixels in which the target pixel is at the center.
|-
|
<div><div><center>[[Image:exampleSliceAveragingTargetPixels.jpg]]</center></div> </div>
|}


<li>Click OK to close the dialog box.</li>
</div>


<li>You must restart of MIPAV for the changes to take effect. To exit MIPAV, select File &raquo; Exit. Then, restart the software.</li>
Because 2D images contain only one slice, the only option possible under Kernel Thickness in the Mean Filter dialog box is slice averaging-the Apply slice kernel option. The Apply volume kernel option, which performs volume averaging, is dimmed. However, both slice averaging and volume averaging are available for 3D images. Although slice averaging is the default value, users can choose volume averaging instead by selecting the Apply volume kernel option.
</ol>


Now, when more memory is needed to perform a certain task, MIPAV allocates it until the memory reaches the maximum heap size you specified. You can also access this dialog anytime and change the memory allocation parameter as you wish.
For slice averaging, the default kernel size is 3 x 3, but the following kernel sizes are available: 5 x 5, 7 x 7, 9 x 9, or 11 x 11. For volume averaging, the default kernel size is 3 x 3 x 3. However, you can select one of the following sizes instead: 5 x 5 x 5, 7 x 7 x7, 9 x 9 x 9, or 11 x 11 x 11.


<div id="LinuxMemory"></div>
{| border="1" cellpadding="5"
|+ <div>'''Figure 2. Image processing using the Mean algorithm''' </div><div>This figure depicts slice averaging and volume averaging applied to the whole image with various size kernels as noted. </div>
|-
|
[[Image:exampleMeanProcessing.jpg]]
|}


=== Linux users: adjusting memory settings ===
For color images the default is to obtain the means of the red, green, and blue channels. However, if users clear the Red channel, Green channel, or Blue channel check boxes, MIPAV only performs mean averaging on the color channels that are selected.


To change the amount of memory allocated for MIPAV use, you need to run MIPAV using an account that has write-permission to the directory where MIPAV is installed, such as an administrator. The heap size is set in the mipav.lax file located in the directory where MIPAV is installed. E.g. <span style="font-family:courier">/usr/share/mipav </span>(and not within your own user mipav folder, e.g. <span style="font-family:courier">~/mipav</span>). Therefore, you need to run MIPAV with the appropriate permissions to modify files in that directory for the one time when you use the memory allocation tool.
==== Image types ====


<ol>
You can apply this algorithm to all image data types and to 2D, 2.5D, and 3D images.
<li> Login to your computer under the administrative account, or under the user account who installed MIPAV.</li>
<li> Select Help &raquo; Memory Allocation in the Main MIPAV window. [[#ChangeJava | The Check java-runtime Memory Allocation dialog box]] opens.</li>
<li> In the dialog box, change the maximum heap size number so it reflects the maximum amount of memory you might need.</li>
<li> Click OK to close the dialog box.</li>
<li> You must restart of MIPAV for the changes to take an effect. To exit MIPAV, select File &raquo; Exit. Then, restart the software.</li>
</ol>


<div id="MacMemory"></div>
==== Special notes ====


=== Mac OS users: adjusting memory settings ===
None.


Follow the instructions provided to the [[#LinuxMemory | Linux users]]. The only difference is that in Mac OS the <span style="font-family:courier">mipav.lax</span> file is called <span style="font-family:courier">mipav.command.lax</span>, but it looks just the same.
==== References ====


<div id="MipavLax"></div>
Refer to the following reference for more information about this algorithm:
=== mipav.lax file ===


To adjust memory settings, MIPAV needs an access to the <span style="font-family:courier">mipav.lax</span> file located in the directory where MIPAV is installed. That’s why you need the appropriate permissions to make changes in this file. See also: [[MIPAV configuration files#LaunchAnywhere | MIPAV LAX files.]]
Raphael C. Gonzalez and Richard E. Woods. ''Digital Image Processing'', Second Edition (Upper Saddle River, New Jersey: Prentice-Hall, Inc., 2002), pp. 116-123.


'''mipav.lax file: the allocating memory section'''
=== Applying the Mean algorithm ===


<blockquote>
To run this algorithm, complete the following steps:
LAX.NL.JAVA.OPTION.JAVA.HEAP.SIZE.INITIAL <br />


&#35;  ----------------------------------------- <br />
# Open an image. As an option, delineate a VOI.
# Select Algorithms &gt; Filter (spatial) &gt; Mean. The Mean Filter dialog box (Figure 3) opens.
# Complete the information in the dialog box.
# Click OK.


&#35; Java start up heap size<br />
; The algorithm begins to run, and a pop-up window appears with the status. The following message appears: "Filtering image."
; When the algorithm finishes running, the pop-up window closes, and the results either appear in a new window or replace the image to which the algorithm was applied.


lax.nl.java.option.java.heap.size.initial=1048576000 <br />
<div>


&#35;  LAX.NL.JAVA.OPTION.JAVA.HEAP.SIZE.MAX <br />
{| border="1" cellpadding="5"
 
|+ <div>'''Figure 3. Mean Filter dialog box''' </div>
&#35;  ------------------------------------- <br />
|-
 
|
&#35;  Java maximum heap size <br />
<div>'''Kernel size''' </div>
 
|
lax.nl.java.option.java.heap.size.max=1048576000 <br />
<div>Specifies the size of the ''k'' x ''k'' neighborhood that extends in all directions by (''k ''- 1)/2 from the center pixel. </div>
</blockquote>
| rowspan="7" colspan="1" |
 
<div><div><center>[[Image:dialogboxMean.jpg]]</center></div> </div><div> </div>
Note: For Mac OS <span style="font-family:courier">mipav.lax file</span> is called <span style="font-family:courier">mipav.command.lax</span>, but it looks just the same.
|-
 
|
=== Other situations ===
<div>'''Red channel''' </div>
[[File:OptionsMIpav.png|290px|thumb|right|The MIPAV Options dialog box]]
|
 
<div>Applies the algorithm to the red channel. </div>
If you change the amount of allocated memory (the maximum heap size) and receive the following error message:
|-
<blockquote>
|
"Heap size settings in the environment startup file either do not match those in the Preference file, or are non-existent. Memory Allocation will display so you can ensure this is correct." </blockquote>
<div>'''Green channel''' </div>
 
|
And when you set a new number: in the Change java-runtime Memory Allocation dialog box, the following error message appears:
<div>Applies the algorithm to the green channel. </div>
 
|-
<blockquote>"Error writing to starting options file. No changes were made."</blockquote>
|
 
<div>'''Blue channel''' </div>
'''In order to fix that problem:'''
|
 
<div>Applies the algorithm to the blue channel. </div>
This is a common message when you have multiple versions of MIPAV installed on your computer and you switch between them. If you don’t want this warning to show up, you can avoid this by un-checking LAX/Preferences memory check option in the mipav.preferences file. This could be done via the MIPAV Options dialog box.
|-
 
|
<ol>
<div>'''New image''' </div>
<li> Select Help &raquo; Mipav Options in the Main MIPAV window. The MIPAV Options dialog box opens.</li>
|
<li> In the dialog box, go to the Other tab.</li>
<div>Shows the results of the algorithm in a new image window. </div>
<li> Un-check the LAX/Preferences memory check box.</li>
|-
<li> Click Apply. The change will take place immediately.</li>
|
</ol>
<div>'''Replace image''' </div>
 
|
<div id="HowMuchMemory"></div>
<div>Replaces the current active image with the newly calculated mean image. </div>
== How much memory does MIPAV require to run? ==
|-
 
|
MIPAV requires a base of at least 10 Mb of random access memory (RAM). However, to correctly display image files and to quantify the data, you need to allocate more memory, use disk swap space, or install additional memory beyond this base. Each time MIPAV is installed, it always defaults to 100 Mb.
<div>'''Whole image''' </div>
 
|
=== What affects memory requirements? ===
<div>Applies the algorithm to the whole image. </div>
 
|-
Memory requirements fluctuate depending on the size and number of image files that are open at the same time. Factors affecting memory requirements are the following:
|
1) the physical size of image files (i.e., 1.2 Mb); 2) the number of images opened, because working on more than one image file at the same time requires more memory.
<div>'''VOI regions''' </div>
 
| rowspan="1" colspan="2" |
'''Note:'''Java provides a method called Garbage Collector that clears all unnecessarily reserved memory. Generally, the software does this automatically, when free memory becomes very limited. However, you can run the Garbage Collector at any time to free memory (refer to [[#HowFreeMemory | How can I free memory?]] ). <br />
<div>Applies the algorithm to the volumes (regions) delineated by the VOIs. </div>
 
|-
<div id="MemoryNeeded"></div>
|
=== How can I determine the amount of additional memory needed? ===
<div>'''Apply slice kernel''' </div>
 
| rowspan="1" colspan="2" |
To determine the amount of additional memory needed:
<div>Applies the kernel to only the specific slice in the dataset </div>
<ol>
|-
<li> Multiply the size of the largest image file that you want to process by 10.</li>
|
<li>Multiply the results by the number of image files that you want to display simultaneously.</li>
<div>'''Apply volume kernel''' </div>
<li> Add this amount to the 10-Mb base memory to result in the total amount of memory typically needed.</li>
| rowspan="1" colspan="2" |
</ol>
<div>Applies the kernel to all of the slices-that is, the entire volume-in the dataset. </div>
 
|-
==== Example 1: Memory calculation====
|
 
<div>'''OK''' </div>
If an image file is 2 Mb and you only want to display one image file at a time, you must allocate an additional 20 Mb of RAM to the base memory of 10 Mb to result in a memory requirement of 30 Mb.
| rowspan="1" colspan="2" |
 
<div>Applies the mean algorithm according to the specifications in this dialog box. </div>
<blockquote>
|-
2 Mb Size of image file x 10
|
<hr width="20%" />
<div>'''Cancel''' </div>
20 Mb Memory required for displaying and processing 1 image file
| rowspan="1" colspan="2" |
 
<div>Disregards any changes that you made in this dialog box and closes the dialog box. </div>
+
|-
 
|
10 Mb Base memory required for running MIPAV
<div>'''Help''' </div>
<hr width="20%" />
| rowspan="1" colspan="2" |
30 Mb Total memory required
<div>Displays online help for this dialog box. </div>
</blockquote>
|}
 
==== Example 2: Memory calculation ====
 
If the largest size image file is 2 Mb and you want to display 3 image files simultaneously, multiply 2 Mb by 10. Then multiply that sum by 3. Add that total to the base memory of 10 Mb to yield a memory requirement of 70 Mb.
 
<blockquote>
2 Mb Largest size image file x 10
<hr width="20%" />
20 Mb Memory required for displaying 1 image file
x 3 Number of images to display and process simultaneously
<hr width="20%" />
60 Mb Memory required to display 3 image files
 
+
 
10 Mb Base memory required for running MIPAV
<hr width="20%" />
70 Mb Total memory required
</blockquote>
 
=== How can I determine how much memory is currently being used? ===
[[File:MemoryUsage.jpg|400px|thumb|right|The Memory Monitor dialog box]]
 
In the main MIPAV window, select Help &raquo; Memory Usage (or press '''Ctrl+M'''). The Memory Monitor dialog box appears. The dialog box shows how much memory is allocated and the amount of memory that is being used. The graph displays a pictorial representation of the ratio of allocated memory and amount of memory used. It shows the memory usage during the past 3 minutes and 45 seconds.
 
'''Note: '''You can leave this window open if you want to constantly monitor your memory resources.<br />
 
<div id="HowFreeMemory"></div>
 
== How can I free memory? ==
 
 
[[File:GarbageCollector.jpg|frameless]] As Java-based programs run, they often leave old variables, objects, or constructors in memory. For instance, if you delineate a VOI, the coordinates of the contours may remain in memory even after you close the image. Java provides a method called the ''garbage collector'' (or ''memory recycling'') that automatically freeing objects that are no longer referenced by the program and clears all unnecessarily reserved memory. Generally, the software does this automatically when free memory becomes very limited. However, you can run the garbage collector at any time to free memory by clicking the Garbage Collector button.
 
=== To free memory, do the following procedure periodically: ===
 
<ul>
<li> Click the Garbage Collector button on the main MIPAV window.</li>
<li> Select Help &raquo; Memory Usage in the main MIPAV window. The Memory Monitor dialog box appears. Click Free Memory. The system clears all unnecessarily reserved memory.</li>
</ul>
 
 
== Videos ==
This video tutorial explains how to load images into MIPAV and change the memory allocation - [http://www.youtube.com/embed/npSYWYJa530 play].
 
== See also: ==
*[[Getting Started Quickly with MIPAV]]
*[[Allocating Memory in MIPAV]]
*[[Opening and loading image files]]
 
Next: [[FAQ: Customizing MIPAV]]


[[Category: Help]]
</div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 18pt; margin-right: 0pt; margin-top: 6pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none; vertical-align: baseline"><font size="11pt"><font color="#000000"><br />


[[Category: FAQ]]
[[Category:Help]]
[[Category:Help:Algorithms]]

Revision as of 18:25, 18 May 2012

This algorithm provides a simple way of reducing noise either in an entire image or in a delineated VOI in the image where

Mean = sum of all pixels in the kernel / total number of pixels in the kernel

This is one method of low-pass filtering, which is sometimes referred to as neighborhood averaging.

Background

In applying this algorithm, MIPAV first defines a region, either in the whole image or in the delineated VOI, over which it replaces a target pixel value with the average value over the kernel of pixels in which the target pixel is at the center. That is, for the target pixel:

where k '= kernel,' s = kernel size, and I = image.

For slice averaging (Figure 1] and (Figure2), the kernels are odd-length squares (for example, 3 x 3). The processing time increases with the square of the kernel length. For volume averaging ( Figure 2), the kernels are odd-length cubes (such as 5 x 5 x 5), and the processing time increases with the cube of the kernel length. Refer to Figure 2 for examples of slice and volume averaging.

Note that the term average does not always represent the mean. If fact, there are three types of average: the commonly used mean, the median, and the infrequently used mode. The mean is defined as the sum of the values in a group divided by the number of values in the group. The median value is the value that has the same number of values greater and less than it. The mode is the value with the greatest number of occurrences.

If part of the neighborhood kernel falls outside the image when the pixel is on or near the boundary, MIPAV only uses that portion of the kernel inside the image.

Exampleicon.gif

Example: Consider the upper right corner pixel in a 2D image if a 3 x 3 kernel is used. In this case, when the algorithm is applied, MIPAV uses only the target pixel and its lower, left, and diagonal left lower neighbors. It then divides the sum of these four pixels by 4.


If you select the New image option, MIPAV places the resulting image in a new image window. If you select the Replace image option, MIPAV returns the changed picture to the same image window. If you delineate a VOI on the image and select VOI regions, then MIPAV replaces the original value of a pixel inside the VOI with the mean value of the kernel that contains the pixel at its center. The pixel values outside the VOI remain unchanged.

Figure 1. Slice averaging
In slice averaging, MIPAV defines a region and replaces the target pixel value with the average value over the kernel of pixels in which the target pixel is at the center.
ExampleSliceAveragingTargetPixels.jpg

Because 2D images contain only one slice, the only option possible under Kernel Thickness in the Mean Filter dialog box is slice averaging-the Apply slice kernel option. The Apply volume kernel option, which performs volume averaging, is dimmed. However, both slice averaging and volume averaging are available for 3D images. Although slice averaging is the default value, users can choose volume averaging instead by selecting the Apply volume kernel option.

For slice averaging, the default kernel size is 3 x 3, but the following kernel sizes are available: 5 x 5, 7 x 7, 9 x 9, or 11 x 11. For volume averaging, the default kernel size is 3 x 3 x 3. However, you can select one of the following sizes instead: 5 x 5 x 5, 7 x 7 x7, 9 x 9 x 9, or 11 x 11 x 11.

Figure 2. Image processing using the Mean algorithm
This figure depicts slice averaging and volume averaging applied to the whole image with various size kernels as noted.

ExampleMeanProcessing.jpg

For color images the default is to obtain the means of the red, green, and blue channels. However, if users clear the Red channel, Green channel, or Blue channel check boxes, MIPAV only performs mean averaging on the color channels that are selected.

Image types

You can apply this algorithm to all image data types and to 2D, 2.5D, and 3D images.

Special notes

None.

References

Refer to the following reference for more information about this algorithm:

Raphael C. Gonzalez and Richard E. Woods. Digital Image Processing, Second Edition (Upper Saddle River, New Jersey: Prentice-Hall, Inc., 2002), pp. 116-123.

Applying the Mean algorithm

To run this algorithm, complete the following steps:

  1. Open an image. As an option, delineate a VOI.
  2. Select Algorithms > Filter (spatial) > Mean. The Mean Filter dialog box (Figure 3) opens.
  3. Complete the information in the dialog box.
  4. Click OK.
The algorithm begins to run, and a pop-up window appears with the status. The following message appears
"Filtering image."
When the algorithm finishes running, the pop-up window closes, and the results either appear in a new window or replace the image to which the algorithm was applied.
Figure 3. Mean Filter dialog box
Kernel size
Specifies the size of the k x k neighborhood that extends in all directions by (k - 1)/2 from the center pixel.
DialogboxMean.jpg
Red channel
Applies the algorithm to the red channel.
Green channel
Applies the algorithm to the green channel.
Blue channel
Applies the algorithm to the blue channel.
New image
Shows the results of the algorithm in a new image window.
Replace image
Replaces the current active image with the newly calculated mean image.
Whole image
Applies the algorithm to the whole image.
VOI regions
Applies the algorithm to the volumes (regions) delineated by the VOIs.
Apply slice kernel
Applies the kernel to only the specific slice in the dataset
Apply volume kernel
Applies the kernel to all of the slices-that is, the entire volume-in the dataset.
OK
Applies the mean algorithm according to the specifications in this dialog box.
Cancel
Disregards any changes that you made in this dialog box and closes the dialog box.
Help
Displays online help for this dialog box.