![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323905/image.png)
I want to change the black background of my image into white.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Keerthi D
le 29 Juin 2020
Commenté : Image Analyst
le 23 Août 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323902/image.jpeg)
I want to only change this black background to white color (without any other change.)
0 commentaires
Réponse acceptée
Image Analyst
le 29 Juin 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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323905/image.png)
12 commentaires
Image Analyst
le 23 Août 2020
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!