mat2gray implementation affecting output

2 views (last 30 days)
Hi everyone,
I am using a program called Multem to generate simulated TEM nanoparticle images. I have adapted the program to produce images that reflect detector influence on the images. I include the modulation transfer function (MTF) as well as the noise transfer function (NTF) of the detector. These two properties describe how the signal and noise are influenced by the detector respectively. The noise I am primarily focusing on is shot noise, which I include using poissrnd(A), where A is the electron dose per image. The values of A vary from 2.6e6 to 8.07e7.
The code structure is as follows:
img1 = noiseless image (output from Multem)
%including the MTF
img2 = fft(img1).*(MTF) ----(1)
img3= ifft(img2) ----(2)
%including noise
t= total dose per image
img4 = poissrand(t); ----(3)
img5 = fft(img4).*(NPS) ----(4)
img6 = iff(img5); ----(5)
%multiplying MTF attenuated signal by noise attenuated by the NPS
img7= img3.*img6 ----(6)
%saving image as tiff
imwrite(mat2gray(img7),...'.tif') ----(7)
I run into the following issues when I use mat2gray;
When I do use it on steps (2,3,5, 6 and 7);
  • the noise standard deviation is the same for all A values and the noise appears exaggerated even for high A values
When I exclude it on step 5;
  • the noise standard deviation is the same for all A values and the noise appears low even for low A values
When I use it only in writing the final images the outcome is almost no noise at all;
Also, when I don't use it at all steps images I retrieve white images with no information.
I have attempted several other combinations but the outcomes have remained the same either there is too much or too little or no noise at all. When is it appropriate to use mat2gray and when is it not? Typically the data are meant to reflect dose dependence but in this case I am not getting that.
Any advice and pointers are welcome,
Thank you
  1 Comment
DGM
DGM on 26 Apr 2021
mat2gray(A) is going to normalize the data to the range of its extrema. Any offset information is lost. The minimum (e.g. 2E6) gets mapped to 0. The maxima gets mapped to 1. If this is going to mess up subsequent calculations, you may try specifying the range which mat2gray() uses when normalizing. Given the extreme offset though, you might run into precision issues with the numeric class used when writing to tiff. I'm not sure of what to recommend, and I'm not even sure this information is helpful to you.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Apr 2021
When you use imwrite of double precision data,
"If A is a grayscale or RGB color image of data type double or single, then imwrite assumes that the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values. If the data in A is single, convert A to double before writing to a GIF or TIFF file."
imwrite() never outputs Tiff in floating-point format.
There is a file exchange contribution that uses the Tiff class to write tiff in single or double precision.
This is the reason why you get white if you do not use mat2gray: your values are floating point greater than 1, and floating point values greater than 1 are treated as 1 (maximum intensity)
  13 Comments
Walter Roberson
Walter Roberson on 3 May 2021
If you can save as double precision, then you should probably avoid mat2gray()
Arthur Moya
Arthur Moya on 3 May 2021
Thank you@Walter Roberson. I think I get it now.
Regards,
Arthur

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!