MATLAB Answers

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

5 views (last 30 days)
Keerthi  D
Keerthi D on 29 Jun 2020
Commented: Image Analyst on 5 Jul 2020
rgbImage=imread('C:\Users\KeerthiDev\Desktop\tomato_dataset\Tomato_late_blight_water_mold\late130.jpg');
%figure,imshow(rgbImage, []);
rgbImage = imadjust(rgbImage,stretchlim(rgbImage),[]);
rgbImage = imreducehaze(rgbImage);
figure,imshow(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));
figure,imshow(maskedRgbImage);
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.)

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 29 Jun 2020
Try this:
rgbImage = imread('image.png');
subplot(2, 2, 1);
imshow(rgbImage);
mask = all(rgbImage == 0, 3);
% Take the largest blob
mask = bwareafilt(mask, 1);
subplot(2, 2, 2);
imshow(mask);
maskedRgbImage = rgbImage + uint8(255 * repmat(mask, [1, 1, 3]));
subplot(2, 2, 3);
imshow(maskedRgbImage);

  10 Comments

Show 7 older comments
Image Analyst
Image Analyst on 2 Jul 2020
I'm not sure what you're wanting. Do you want the surround to be white or black? Do you want the image cropped smaller or not? If so, where would you want the cropping rows and columns to be?
Keerthi  D
Keerthi D on 5 Jul 2020
surround should be white.my problem is,some shadows are presented inside and outside of the leaf.how to remove both are.

Sign in to comment.


Translated by