Using MATLAB as an image editor?

7 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2012-9-26
编辑:Image Analyst 2012-9-26
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 个评论
Image Analyst
Image Analyst 2012-9-26
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by