Dear All,
I have image unknown.png, I want to covert the size and map same with the image image2988.png (28x28 uint8)
Because my unknown.png is 2320x2864x3 uint8
I tried this command
%testing
testing = imread('unknown.png');
testing1 = imresize(testing, [28 28])
but the image still have 28x28x3 uint8 . What I want is just 28x28 uint8 only. Why the number of 3 have

3 comentarios

Stephen23
Stephen23 el 2 de Ag. de 2023
Editada: Stephen23 el 2 de Ag. de 2023
"Why the number of 3 have"
IMRESIZE does not convert an RGB image into a grayscale or select color channels or whatever unspecified operation you expect to occur. IMRESIZE uses a fairly universal definition of "resizing" an image: it changes the number of row/columns an image has, exactly as its documentation clearly states "If A has more than two dimensions, then imresize only resizes the first two dimensions". It is highly recommended to read the documentation for functions that you are using, to learn what those functions do and how to call them properly. Reading the documentation is faster and more reliable than guessing.
If you want one channel of your image then use indexing.
If you want to convert an RGB (e.g. truecolor) image to grayscale then use IM2GRAY:
mohd akmal masud
mohd akmal masud el 2 de Ag. de 2023
Thats means the number of 3 showing the image is RGB.
Stephen23
Stephen23 el 2 de Ag. de 2023
Editada: Stephen23 el 2 de Ag. de 2023
"Thats means the number of 3 showing the image is RGB."
Probably, but not necessarily: it might be an Lab image, or use any of countless other colorspaces.
The number of channnels does not uniquely determine what colorspace an image is encoded with, that can only be determined with prior-knowledge (e.g. the color encoding stored as part of in an image file).

Iniciar sesión para comentar.

 Respuesta aceptada

Shubham
Shubham el 2 de Ag. de 2023

0 votos

Hi Mohd,
The value "3" in the statement "2320x2864x3 uint8" refers to the number of color channels in the image. In this case, the image has 3 color channels, namely Red, Green, and Blue (RGB). Each pixel in the image is represented by three 8-bit unsigned integers (uint8) for the intensity values of each color channel.
If you want to convert the resulting image to grayscale and have a size of "28x28 uint8" with a single channel, you can use the "rgb2gray" function in MATLAB. Details
Also refer to this MATLAB Answer for more insight.

Más respuestas (1)

Image Analyst
Image Analyst el 2 de Ag. de 2023
"I have image unknown.png, I want to covert the size and map same with the image image2988.png (28x28 uint8)" so I take it that the unknown.png is an RGB image and image2988.png is an indexed image and you want to convert the unknown image to an indexed image, using the same colormap as image2988, and then resize it. So you can do this (untested)
% Read in reference image and it's colormap
[indexedImage, cmap] = imread('image2988.png');
% Get it's size.
[rows, columns, numberOfColorChannels] = size(indexedImage)
if isempty(cmap)
% If colormap does not exist, use gray scale.
cmap = gray(256);
end
% Read in unknown RGB image
unknownImage = imread('unknown.png');
% Resize image. Note this may change colors obviously.
unknownImage = imresize(unknownImage, [rows, columns]); % It's still an RGB image after this.
% Turn into an indexed image using the same colormap as the reference image.
unknownImage = rgb2ind(unknownImage, cmap);
If it doesn't work then let me know and I'll download your zip files and try it and correct it. Or if I didn't understand what you meant when you said you wanted to apply the map of image2988 to unknown, then please explain better.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Productos

Versión

R2023a

Preguntada:

el 2 de Ag. de 2023

Comentada:

el 30 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by