Borrar filtros
Borrar filtros

Image Processing with data of type single

7 visualizaciones (últimos 30 días)
Sai Prakash Reddy Konda
Sai Prakash Reddy Konda el 9 de Nov. de 2018
Comentada: Guillaume el 14 de Nov. de 2018
Hi,
I need your help in this issue. I have an image(X) with data type 'single'. When I am trying to add noise to this image using "imnoise"(say J = imnoise(X,'salt & pepper',0.5);), my output(noise corrupted) image(J) is loosing the all the decimal components(well the name of the data type is still single, but it looses all the decimal parts of the data) and data is getting rounded to 0's and 1's.
Is there any way that I can add noise to the image and can still preserve the decimal part, so that I do not loose any information?.
Kindly help me out.
Thanks in advance.
  4 comentarios
Walter Roberson
Walter Roberson el 12 de Nov. de 2018
How do you know that the image() is getting converted to integer?
L C
L C el 12 de Nov. de 2018
May be the range of the input image X is not in [0 1].
You can do this X = X/255;
or
X = im2single(X);

Iniciar sesión para comentar.

Respuestas (2)

Bjorn Gustavsson
Bjorn Gustavsson el 12 de Nov. de 2018
For sake of simplicity - convert every image to double if you possibly can memory-wise. That way you won't have to deal with obscure implicit typecastings and other numerical issues (integer divisions ,ffts on and on...).
HTH

Guillaume
Guillaume el 12 de Nov. de 2018
Editada: Guillaume el 12 de Nov. de 2018
Despite your statement, at some point, the image must have been converted from integer type to single, and the conversion wasn't done properly.
When images are of type single or double matlab expects that the intensities are in the range [0-1]. Anything above 1 is the same as 1 as far as matlab is concerned. So if you were to convert a uint8 image whose range is [0-255] to single naively with single(), the original range would be preserved and for matlab intensity [1-254] would all be the same: 1. The proper way to convert an image to single is with im2single() which will divide the intensities by 255 (for uint8 images) to get the right range.
Indeed, if you apply imnoise to a single image whose intensities are integer in the range [0-255], you'll just get 0s and 1s in your output.
The best solution to your problem is to go back to your code, find where this incorrect conversion occurs and fix it. A workaround is to rescale the intensities yourself. Assuming that the intensity range of your single image is [0-255] (the most common, but check yourself with min and max), then:
X = X/255; %make sure range of intensity is [0-1]
J = imnoise(X,'salt & pepper',0.5)
  6 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 14 de Nov. de 2018
True, the majority will be such images, and therein lies "des pudels kern".
In addition to 8-bit integers there are 16-bit integers and some standard image formats (tiff) allow that and FITS allows 32 and 64 bit int as well.
On you other points I completely agree - the image processing toolbox seems to have "two parrents" or a bit of a "split personality", and perhaps that is understandable though not preferable.
Guillaume
Guillaume el 14 de Nov. de 2018
For info, I've submitted an enhancement request for the documentation of imnoise so that it details the image requirements for the 'salt & pepper' option, the same way it does for all the other options.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by