简体   繁体   中英

matlab: How to convert an rgb image into matrix

I have an image (rgb image) and want to convert it into its equivalent rgb matrices so that I can transform them to their binary equivalent.

Overall I want to get the pixels value of my image.
How can I perform it in matlab ?

I =  imread('filename.xxx');
size(I)
% This should print height width and channels

Access the single channels (assuming your image is rgb):

r = I(:,:,1);
g = I(:,:,2);
b = I(:,:,3);

or, changing the pixel in red channel at position 1,1:

I(1,1,1) = 255;

Why you need to do that I have no clue, images by default are matrices, but remember because rgb images stored in MATLAB are actually 3 layered matrices, in saying that if you were wanting to access elements of an image just use image(y,x,n) or x,y,n I forget lol, where x,y are points on the matrix and n is the layer you want to access, and furthermore the start point in a matrix image is actually 1,1 not 0,0 so be careful when calling elements or modifying elements of a matrix.

See: How to access image's matrix in matlab and scan it to find the specific pixel values?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM