Azzera filtri
Azzera filtri

Could someone please explain what the code means?

2 visualizzazioni (ultimi 30 giorni)
Duncan il 22 Mag 2014
Commentato: Duncan il 22 Mag 2014
function displacements2D
%________________________________________Read images & Shadding correction
%k=input('Enter the image file name: ','s'); % input image; color image
r = rgb(:,:,1); g = rgb(:,:,2); b = rgb(:,:,3);
I would especially like to know about the 3rd last line. What's happening there? Thanks, any help would be appreciated

Risposte (2)

Image Analyst
Image Analyst il 22 Mag 2014
rgb2 is the color image. Then they do an overly complicated way of making a copy of it in rgb. Then they extract out each color channel into separate 2D images r, g, and b. Then they get a gray scale version of the color image which is made up of a weighted combination of the red, green, and blue channel images.

Walter Roberson
Walter Roberson il 22 Mag 2014
The only thing that
does for you other than to copy rgb2 to rgb, is to throw an error in the case that the image read was greyscale instead of RGB. grayscale images would only have one plane instead of 3.
JPEG files cannot store pseudocolor images (which would also be 2D instead of 3D).
JPEG files also cannot store CMYK images (which would have 4 planes instead of 3) -- only TIFF files can store those.
If you wanted to check whether it was 3D or not then that should be done explicitly with ndims
  3 Commenti
Walter Roberson
Walter Roberson il 22 Mag 2014
rgb2(:,:,1:3) means to extract all rows and all columns and planes 1, 2, and 3 of the matrix rgb2. The first position after the "(" is row numbers, the second is column numbers, the third is plane numbers; beyond that would get to higher and higher hyperplanes.
rgb(:,:,2) would be extracting all rows and all columns of the 2nd hyperplane.
In an RGB image, the first hyperplane stores the red information, the second stores the green information, and the third stores the blue information.

Accedi per commentare.


Community Treasure Hunt

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

Start Hunting!

Translated by