Removing background noise from an image

I have two images. The first is background noise + content, and the second is only background noise. I would like to subtract the second image from the first in order to remove noise from the content. Image is in grayscale.

I got confused between the different ways of handling this, as well as the processing of grayscale values ​​in mathematics.

1) First, we can use ImageSubtract[imageOne, imageTwo] .

2) Using ImageDifference[imageOne, imageTwo] , we avoid negative pixel values, but the image is artificial in those places where we had to have negative pixels when using ImageSubtract .

3) We get the values ​​of each pixel using ImageData , subtract each corresponding value and then display the result using Image .

Each of these methods gives different results.

+4
source share
1 answer

For images with real data types, pixel values ​​can be negative, and these three operations are equivalent:

 real1 = Image[RandomReal[1, {10, 10}]]; real2 = Image[RandomReal[1, {10, 10}]]; ImageData[ImageDifference[real1, real2]] == Abs@ImageData [ImageSubtract[real1, real2]] == Abs[ImageData[real1] - ImageData[real2]] Out[4]= True 

But this does not apply to images of integer data types. This is due to the fact that only positive values ​​can be stored in such images, and negative subtraction results are trimmed to zero in the output image:

 int1 = Image[RandomInteger[255, {10, 10}], "Byte"]; int2 = Image[RandomInteger[255, {10, 10}], "Byte"]; 

This is still True :

 ImageData[ImageDifference[int1, int2]] == Abs[ImageData[int1] - ImageData[int2]] 

But these two are different due to clipping:

 ImageData[ImageDifference[int1, int2]] == Abs@ImageData [ImageSubtract[int1, int2]] 

Converting both input images to the data type β€œReal” or β€œReal32” would be less cryptic.

+6
source

All Articles