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

287 views (last 30 days)
I=im2double(I); what is the need for it
  1 Comment
D Joseph
D Joseph on 13 Aug 2015
"I2 = im2double(I) convertsthe intensity image I to double precision, rescalingthe data if necessary". I am not getting this description.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 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 Comments
gunturu gunturu
gunturu gunturu on 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?

Sign in to comment.

More Answers (0)

Categories

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

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!