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

2 views (last 30 days)
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);
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by