I want to change the black background of my image into white.

조회 수: 4(최근 30일)
Keerthi  D
Keerthi D 2020년 6월 29일
댓글: Image Analyst 2020년 8월 23일
%figure,imshow(rgbImage, []);
rgbImage = imadjust(rgbImage,stretchlim(rgbImage),[]);
rgbImage = imreducehaze(rgbImage);
grayImage = rgb2gray(rgbImage);
figure,imshow(grayImage, []);
hFH = imfreehand();
binaryImage = hFH.createMask();
xy = hFH.getPosition;
blackMaskedImage = grayImage;
blackMaskedImage(~binaryImage) = 0;
maskedRgbImage = bsxfun(@times,rgbImage,cast(binaryImage, 'like',rgbImage));
after runing this code to i got the image as shown below
I want to only change this black background to white color (without any other change.)

채택된 답변

Image Analyst
Image Analyst 2020년 6월 29일
Try this:
rgbImage = imread('image.png');
subplot(2, 2, 1);
mask = all(rgbImage == 0, 3);
% Take the largest blob
mask = bwareafilt(mask, 1);
subplot(2, 2, 2);
maskedRgbImage = rgbImage + uint8(255 * repmat(mask, [1, 1, 3]));
subplot(2, 2, 3);
  댓글 수: 12
Image Analyst
Image Analyst 2020년 8월 23일
Well, keep trying. I don't have that paper coded up myself, so you'll have to do it. But it looks like it should remove your shadows.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by