# how to change the background in imshow from black to white

29 views (last 30 days)
Houghton on 19 Aug 2015
Commented: Image Analyst on 22 Aug 2020
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
I want a result that shows the pyramid with a white background.
Thanks
Morteza on 19 Aug 2015
Edited: Morteza on 19 Aug 2015
in fact by counting the number of repeated item you can consider what color is dominated by background color and set the new color as user specify it like input and then set new background color. write GUI to analyze it and do the rest...

Morteza on 19 Aug 2015
Edited: Morteza on 19 Aug 2015
try this save your picture like Untitled.png on your desktop and then call it from MATLAB like below:
clc,clear all
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)
##### 3 CommentsShow 1 older commentHide 1 older comment
Keerthi D on 29 Jun 2020
Edited: Image Analyst on 22 Aug 2020
Sir I tried your code above, but I didn't get.
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)
result is:
Image Analyst on 22 Aug 2020
Sure, but please post it in a new post, not tacked onto a 5 years old post from someone else.

hf fh on 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
sach on 11 Mar 2019
hey dude, i did. it came out just fine