Using MATLAB as an image editor?

6 visualizzazioni (ultimi 30 giorni)
Tyler
Tyler il 26 Set 2012
I know that MATLAB isn't the simplest tool to edit photos, yet here I am. I am trying to alter the colors of a photo by using MATLAB by certain percentages for red, green, and blue. I am aware of how MATLAB interprets .jpg's with three layers in RGB order, yet I am not sure where I am going wrong. So far I have:
>>a=imread('file_name','jpg');
>>a=0*a(:,:,1);
>>image(a)
Since red is the first layer, shouldn't my image look the same but just be stripped of all red? My other concern is that it changes my 637x800x3 matrix for the original image to just 637x800. Is this a concern?
Also, if I wanted to alter all three layers then stack them again to get a single image, how would I go about doing that with 3 separate 637x800 matrices?

Risposta accettata

Image Analyst
Image Analyst il 26 Set 2012
Modificato: Image Analyst il 26 Set 2012
You just redefined "a" to be zero times its red channel. Which gives an all-zero grayscale image the same size as your original "a"s lateral dimensions. Try this:
a(:,:,1) = 0;
image(a);
To create an rgb image from 3 grayscale images, use cat():
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
  3 Commenti
Walter Roberson
Walter Roberson il 26 Set 2012
Modificato: Walter Roberson il 26 Set 2012
a(:,:,2) = a(:,:,2) * 1.10;
Image Analyst
Image Analyst il 26 Set 2012
Note: Walter's code will keep your "a" as uint8 (because MATLAB does the conversion automatically) and allow it to be displayed. If you ever do something to turn your image into a floating point image, like a = single(a)*1.15, then you'd need to either cast it back to uint8 or pass your array into im2double. Currently MATLAB has a quirk where a floating point image must be in the range 0-1 or else you'll get just all black or all white. (I've asked that that be changed so that something like imshow(a, []) will work for color images just like it does for grayscale images.) Just something to be aware of.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by