필터 지우기
필터 지우기

Using MATLAB as an image editor?

조회 수: 7 (최근 30일)
Tyler
Tyler 2012년 9월 26일
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
Walter Roberson
Walter Roberson 2012년 9월 26일
편집: Walter Roberson 2012년 9월 26일
a(:,:,2) = a(:,:,2) * 1.10;
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by