IMG must be of one of the following classes:

Post Reply
matlab1
Site Admin
Posts: 4797
Joined: Thu Dec 15, 2016 9:30 am
Contact:

IMG must be of one of the following classes:

Post by matlab1 »

IMG must be of one of the following classes:
matlab1
Site Admin
Posts: 4797
Joined: Thu Dec 15, 2016 9:30 am
Contact:

Re: IMG must be of one of the following classes:

Post by matlab1 »

solution :


uint8 and uint16 mostly used for image in MATLAB.



Overview of Image Class Conversions
You can convert uint8 and uint16 image data to double using the MATLAB® double function. However, converting between classes changes the way MATLAB and the toolbox interpret the image data. If you want the resulting array to be interpreted properly as image data, you need to rescale or offset the data when you convert it.

For easier conversion of classes, use one of these functions: im2uint8, im2uint16, im2int16, im2single, or im2double. These functions automatically handle the rescaling and offsetting of the original data of any image class. For example, this command converts a double-precision RGB image with data in the range [0,1] to a uint8 RGB image with data in the range [0,255].

Code: Select all

RGB2 = im2uint8(RGB1);

Losing Information in Conversions
When you convert to a class that uses fewer bits to represent numbers, you generally lose some of the information in your image. For example, a uint16 grayscale image is capable of storing up to 65,536 distinct shades of gray, but a uint8 grayscale image can store only 256 distinct shades of gray. When you convert a uint16 grayscale image to a uint8 grayscale image, im2uint8 quantizes the gray shades in the original image. In other words, all values from 0 to 127 in the original image become 0 in the uint8 image, values from 128 to 385 all become 1, and so on.


Converting Indexed Images
It is not always possible to convert an indexed image from one storage class to another. In an indexed image, the image matrix contains only indices into a color map, rather than the color data itself, so no quantization of the color data is possible during the conversion.


For example, a uint16 or double indexed image with 300 colors cannot be converted to uint8, because uint8 arrays have only 256 distinct values. If you want to perform this conversion, you must first reduce the number of the colors in the image using the imapprox function. This function performs the quantization on the colors in the color map, to reduce the number of distinct colors in the image. See Reduce Colors of Indexed Image Using imapprox for more information.


https://www.mathworks.com/help/images/convert-image-data-between-classes.html
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests