Matlab provides a special data type uint8 (8-bit unsigned integer) for images, and images stored in this way are called 8-bit images.
imread stores the grayscale image in an 8-bit matrix, and when it is an RGB image, it is stored in an 8-bit RGB matrix.
Therefore, the data that matlab reads into the image is uint8, and the values in matlab are generally stored and operated in double type (64 bits). Therefore, it is necessary to convert the image to double format before operation,
I2=im2double(I1) % Convert image I1 to double precision type (assuming the graphics matrix range is 0~255)
or
I64=double(I8)/255; %uint conversion If it is not converted into double
, the calculation will overflow.
That is to say, when using uint8 for display, use double
im2double(): convert the image array to double precision type
im2uint8(): convert the image array to unit8 type
im2uint16(): convert the image array to unit16 type
imread stores the grayscale image in an 8-bit matrix, and when it is an RGB image, it is stored in an 8-bit RGB matrix.
Therefore, the data that matlab reads into the image is uint8, and the values in matlab are generally stored and operated in double type (64 bits). Therefore, it is necessary to convert the image to double format before operation,
I2=im2double(I1) % Convert image I1 to double precision type (assuming the graphics matrix range is 0~255)
or
I64=double(I8)/255; %uint conversion If it is not converted into double
, the calculation will overflow.
That is to say, when using uint8 for display, use double
im2double(): convert the image array to double precision type
im2uint8(): convert the image array to unit8 type
im2uint16(): convert the image array to unit16 type