Image Calculator

From MIPAV
Jump to: navigation, search

This algorithm adds, subtracts, multiplies, and divides, etc. the pixel values of one image by the pixel values of another image. In addition, two images can be ANDed, ORed or XORed together. Also, more advanced operator expressions can be entered in the dialog text field.

Background

Image Calculator performs arithmetic and logical operations between two images selected from popup menus.

The commands in the main Image Calculator dialog box take the pixel values of Image A, and then add, subtract, multiply, etc. them to the pixel values of Image B. For 2D and 3D images the specified operation is performed on all image slices. Refer to Figure 35.

The advanced dialog options allow performing advanced math operations on both images and also performing math operations on the selected image using the specified constant, e.g. Image A*C, where C is a constant.

clip mode

When clip mode is selected and the result value is greater than the maximum value of Image A's data type, the value is clamped at the maximum value of Image A's data type. When clip mode is selected and the result value is less than the minimum value of Image A's data type, then the value is clamped at the minimum value of Image A's data type. See Figure 35.

promotion mode

When the Promote Destination Image Type mode is selected and the result value is not within the legal range of Image A data type, then the result image type is promoted from the default of the Image A data type to a new data type with a data type range capable of expressing the minimum and maximum values.

Promotion sequence:

Boolean is promoted to byte, byte is promoted to unsigned byte, unsigned byte is promoted to short, short is promoted to unsigned short, unsigned short is promoted to integer, integer is promoted to unsigned integer, unsigned integer is promoted to long, long is promoted to float, and float is promoted to double. Double is not promoted.
Color with 3 bytes is promoted to color with 3 unsigned shorts, and color with 3 unsigned shorts is promoted to color with 3 floats. Color with 3 floats is not promoted.
Complex is promoted to double complex.
Double complex is not promoted.

image types

You can apply Image Calculator to all 2D and 3D color and grayscale images. Image A and Image B must have the same number of dimensions and the length of every dimension in Image A must equal the length of the same dimension in Image B. Also, both Image A and Image B must be color images, or both Image A and Image B must be black and white images. The Image Calculator will not accept one black and white Image And one color image. There are no other restrictions on data type.

Image calculator options

Add

Adds the pixel values of Image A to the pixel values of Image B. Basically, this operation adds the colors of the overlay to the background causing the two images ether overflow, or saturate. However, if the added colors excess the color limits, the color will be capped (or clamped) and the result will not necessarily be as you expect.

Figure 23. Adding Image A and Image B

ImageAPixelValues1.jpg

ImageBPixelValues1.jpg

ImageAIMageBPixelValuesAdd1.jpg

Image A sample point (255.0,0.0,255.0)
Image B (0.0,12.0,255.0)
Result= Image A Image B (255.0,12.0,255.0)

AND

Does AND of the Image A and the specified Image B. For each pixel in Image A, the Image A pixel value is set to zero, if either the Image A pixel value equals zero, or corresponding Image B pixel value equals zero. Otherwise, the Image A pixel value is left unchanged.


Figure 24. ANDing images

AndImageA.jpg

AndImageB.jpg

AndImageAImageB.jpg

Image A
Image B
Result=(Image A AND Image B)

Average

Average of two images is calculated as (Image A Image B)/2.


Figure 25. Averaging images

AndImageA.jpg

File:MIPAV Utilities107.gif

AVERAGEImageAImageB.jpg

Image A
Image B
(Image A Image B)/2

Maximum

RGB values for pixels in the Image A and the corresponding RGB values for the Image B are compared, and then replaced with the greater RGB values. As shown in Figure 26 below, for a chosen point, it took MAX R=12.0 from Image B, MAX G=30.0 from Image A, and MAX B=243.0 from Image A.

Figure 26. Maximum (Image A; Image B)

MAXIMUMImageAVOI.jpg

MAXIMUMImageBVOI.jpg

MAXIMUMImageAImageB.jpg

Image A, for the selected point RGB is (0.0, 30.0, 243.0)
Image B, RGB (12.0, 0.0, 44.0)
Result=MAX (Image A, Image B), RGB (12.0, 30.0, 243.0)

Minimum

RGB values for pixels in the Image A and the corresponding RGB values for the Image B are compared, and then replaced with the minimum RGB values. As shown in Figure 27 below, for a chosen point, it took MIN R=0.0 from Image A, MIN G=00.0 from Image B, and MIN B=44.0 from Image B.


Figure 27. Minimum(Image A; Image B)

MAXIMUMImageAVOI.jpg

MAXIMUMImageBVOI.jpg

MINIMUMImageAImageB.jpg

Image A, for the selected point RGB is (0.0, 30.0, 243.0)
Image B, RGB (12.0, 0.0, 44.0)
Result=MIN (Image A; Image B), RGB (0.0, 0.0, 44.0)

Multiply

Multiplies the Image A pixel values by the Image B pixel values. In clip mode, for RGB images with byte values, results greater than 255 are set to 255. This method works very well if one image (either A, or B) is basically black or gray, or just has a light background, see Figure 28. If both images are color images, then you may get strange results. This technique is also perfect for overlaying line drawings, diagrams or images on an image with very light white or colored background. See also "clip mode".


Figure 28. Multiply(Image A; Image B)

MAXIMUMImageAVOI.jpg

ImageBGrayscale.jpg

MultiplyImgeAImageBGrayscale.jpg

Image A
Image B
Image A*Image B

Difference

The difference operation is a sequence of two operations. First, a subtraction operation is performed. Then, the absolute value of the result of the subtraction operation is taken. The variation between the colors black and white difference will produce a maximum result of white. However, any colors which are the same will produce black. You can use this function to see where images are similar and where they differ.


Figure 29. Difference (Image A; Image B)

XORImageA.jpg

MAXIMUMImageBVOI.jpg

DifferenceImageAImageB.jpg

Image A
Image B
Image A-Image B

Divide

Divides the pixel values of Image A by the specified Image B. A positive number divided by zero could yield either the maximum positive value, or positive infinity. A negative number divided by zero could yield either the maximum negative value or negative infinity. Zero divided by zero could yield either zero or not a number.


Figure 30. Dividing images

AndImageA.jpg

AndImageB.jpg

DivideImageAImageB.jpg

Image A
Image B
Image A/Image B

See also:

Image Calculator: OR