# What do these sentences mean in MATLAB.

1 view (last 30 days)
abory kikla on 29 Mar 2016
Commented: Walter Roberson on 29 Mar 2016
Hello
What does it mean follows :
Class of image
Determine Class of image
Data type conversation
And how to use it to create a color array. Examples please
Walter Roberson on 29 Mar 2016

Walter Roberson on 29 Mar 2016
If you have the data stored in the variable YourArray then
class(YourArray)
tells you the class of the image. It might be uint8 or double (both are common) or any of the other numeric data types. It could even be logical.
MATLAB treats images differently depending on which datatype is being used. For any of the integer data types, MATLAB treats 0 as black and treats intmax of the class (such as 255 for uint8) as being full signal. For double or single images, 0 is black and 1 is full strength, for RGB images or grayscale images. (It is also possible to have pseudocolor images for which the numbers would be positive integers and would be treated as indexes into a color table.)
"Determine the class of the image" can be done by calling class() and passing in the name of the variable that holds the image data. Also, if you have a file name, you can examine the output of imfinfo() applied to the file name.
It is also important to know whether the image data is 2 dimensional or 3 dimensional. 3 dimensional arrays must be RGB images, and the data for them must be directly given by the integer value for uint8 or uint16, or must be given by the 0 to 1 range for single or double precision. 2 dimensional arrays can be grayscale or binary or pseudocolor or arbitrary intensity to be mapped to color later.
You would normally create a color image by using imread() to read it in.
If you need to create one "manually" then create a 3 dimensional matrix. For example,
YourImage = zeros(64, 80, 3, 'uint8'); %64 high by 80 wide RGB
YourImage(1:32, :, 1) = 127;
YourImage(33:end, :, 1) = 200;
YourImage(:, 20:60, 2) = 53;
YourImage(:,61:end, 3) = 255;
image(YourImage)
If you have individual red and green and blue matrices, then for example
RedMatrix = zeros(64, 80, 'uint8');
RedMatrix(1:32, :) = 127;
RedMatrix(33:end, :) = 200;
GreenMatrix = zeros(64, 80, 'uint8');
GreenMatrix(:, 20:60) = 53;
BlueMatrix = zeros(64, 80, 'uint8');
BlueMatrix(:,61:end) = 255;
YourImage = cat(3, RedMatrix, GreenMatrix, BlueMatrix);
image(YourImage)
abory kikla on 29 Mar 2016
Uh, you're right,, Thank you for the clarification