how to split the png image of size (477x692 ) into [r,g,b] vectors?

1 visualización (últimos 30 días)
I am new to matlab. I have loaded an jpg image and have split the image into [r,g,b] row vectors. The jpg color image has the size as 380x509x3.
jpeg==> img 380x509x3 580260 uint8
function [r, g, b] = split_img(img)
r = img(:,:,1);
g = img(:,:,2);
b = img(:,:,3);
end
The split worked well.
But when I followed the same process with a png image it was throwing an error. Then when I checked the size of a png color image it is as below
png==> img 477x692 330084 uint8
I understood the the png image size is not 3D. But is it not possible to split a png image into [r,g,b] vectors?
The error which I got was
Error in split_img (line 3)
g = img(:,:,2);
Error in main (line 39)
[r, g, b] = split_img(img);
how to resolve the error???
I am attaching the png image also, which is throwing the error.
Thank you in advance.
  2 comentarios
Stephen23
Stephen23 el 10 de Jul. de 2021
Editada: Stephen23 el 10 de Jul. de 2021
Did you look at the image type? It is not an RGB image, it is clearly saved as an indexed image:
Therefore if you want to get RGB values, you will need to convert the indexed image into an RGB image first:

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by