how to change the background in imshow from black to white
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
get(0,'Factory');
set(0,'defaultfigurecolor',[1 1 1]);
whitebg(figure);
set(gcf,'color','white');
set(gca,'color','none');
figure; clf;
imshow(pairOfImages);
The result is this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148243/image.png)
I want a result that shows the pyramid with a white background.
Thanks
1 commentaire
Réponses (2)
Morteza
le 19 Août 2015
Modifié(e) : Morteza
le 19 Août 2015
try this save your picture like Untitled.png on your desktop and then call it from MATLAB like below:
clc,clear all
A = imread('C:\Users\MORTEZA\Desktop\Untitled0.png');
figure(1)
image(A)
[L,W,D] = size(A);
for i = 1:L
for j = 1:W
for k = 1:D
if A(i,j,k) == 0
A(i,j,k) = 255;
end
end
end
end
figure(2)
image(A)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178133/image.png)
3 commentaires
Keerthi D
le 29 Juin 2020
Modifié(e) : Image Analyst
le 22 Août 2020
Sir I tried your code above, but I didn't get.
A=imread('C:\Users\Keerthi Dev\Desktop\matlabwork\seg1.png');
figure(1)
image(A)
[L,W,D] = size(A);
for i = 1:L
for j = 1:W
for k = 1:D
if A(i,j,k) == 0
A(i,j,k) = 255;
end
end
end
end
figure(2)
image(A)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323887/image.png)
result is:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323890/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/323890/image.png)
Sir, please help me to solve my problem
Image Analyst
le 22 Août 2020
Sure, but please post it in a new post, not tacked onto a 5 years old post from someone else.
hf fh
le 19 Sep 2018
I have a grayscale image, Please help me I have a picture and I want to make the background color white I used the previous method but did not good out with me
1 commentaire
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!