Why an image is converted to double using I=im2double(I); in matlab?

90 visualizzazioni (ultimi 30 giorni)
I=im2double(I); what is the need for it
  1 Commento
D Joseph
D Joseph il 13 Ago 2015
"I2 = im2double(I) convertsthe intensity image I to double precision, rescalingthe data if necessary". I am not getting this description.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 13 Ago 2015
MATLAB has two ways of representing RGB and grayscale images.
  • Images can be represented as double precision numbers (or single precision) in the range 0 to 1.
  • Images can also be represented as integer data classes, especially uint8 (unsigned 8 bit integers), in which case the values are the integers 0, 1, 2, ... up to the maximum representatable in the integer class, such as 255. The conversion from integer class to double precision is to switch the numbers to floating point and then divide by the maximum allowed for the class, such as double(ImageData)/255 so 0 still corresponds to 0.0 and 255 corresponds to 1.0
Most of the image file formats store only integers, or "prefer" to store integers.
Sometimes operations on images are easier when the images are represented in floating point. For example if you want to subtract one image from another, if the images are in unsigned integer format, everywhere the second image was greater than the first you would get 0 as the result because unsigned integers cannot represent negative numbers.
There are also some parts of the graphics system, such as AlphaData, that must be in floating point format.
It is therefore not uncommon to want to switch from integer representation to floating point representation. im2double() does that. im2double() knows about all the various integer storage classes and what the proper conversion formula is -- it is not necessarily a "difficult" conversion, but you can count on im2double() to get it right. This is especially valueable when you are allowing the user to select the images to be read in: if you want to be able to support a variety of image file formats that might use different ranges of values, it is better to call a routine that is sure to get the conversion right than to do the conversion yourself and risk an incompatibility.
  11 Commenti
Simon Silge
Simon Silge il 15 Lug 2020
Modificato: Simon Silge il 15 Lug 2020
I might add to it that double can help to preserve higher precision during image manipulation or grayscale conversion as you are not limited to integer values. For example, for grayscale conversion from a 24-bit RGB ( three channels with 8 bit, datatype uint 8) rgb2gray returns a uint8 grayscale by calculating one grayscale intensity value from the three 8-bit color channels. Here you can loose a small part of information (apart from the colors) during this calculation as the unit8 cannot represent numbers like 100.3 or 100.6 but rounds them to 100 and 101.
gunturu gunturu
gunturu gunturu il 8 Mar 2021
function out = TTFIO(image, tao, zeta)
[row col]=size(image);
img = (image - min(image(:)))./(max(image(:)) - min(image(:)));
for j = 1:row
for k = 1:col
if img(j,k) <= tao
enhanced(j,k) = 2*img(j,k)^2;
else
enhanced(j,k) = 1-2*(1-img(j,k))^2;
end
end
end
out=((enhanced).^(tao+zeta));
can someone please explain this? or please kindly tell me any source from where i can learn this?

Accedi per commentare.

Più risposte (0)

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by