How to crop images in Matlab based on Intensity Profiles?

조회 수: 10(최근 30일)
I have an image in Matlab which I want to crop based on the intensity profile. Below is my image.
I want to crop out the blue portion of the image based on the intensity profile. For example, based on the intensity profile, I want to crop the part of the image where the intensity of blue is higher than the other colors. Below is my sample code and example.
hFig = figure ;
subplot(1, 2, 1 );
rgbImage = imread('Intensity1.jpg ');
imshow(rgbImage )
subplot(1, 2, 2 );
croppedImage = rgbImage(200 : 400 , :, :);
In the image above, it can be seen that the blue portions still remain in the image which I don't want. Any help would be very much appreciated. Thank you.
  댓글 수: 13
Warid Islam
Warid Islam 2019년 8월 3일
Hi Image Analyst,
Thank you for the suggestions. I would implement those in the final output.

댓글을 달려면 로그인하십시오.

채택된 답변

awezmm 2019년 8월 3일
Try this where img is your original image:
% get red, green, blue channels
redC = img(:,:,1);
greenC = img(:,:,2);
blueC = img(:,:,3);
% mask where red channel is greater than blue channel and green channel greater than blue channel
mask = redC > blueC & greenC > blueC;
% overlay mask into original image
finalimg = bsxfun(@times, img, cast(mask,class(img)));
  댓글 수: 2

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by