2 different imshow() calls send images to same figure?
Show older comments
I'm trying to open 2 separate figures and display a grayscale image in each figure using imshow. However, when I do so, the title of my first image is removed, but not the image itself. Figure(1) is also renamed to figure(2) while what I want to be figure(2) is named figure(1).
I think the issue is that imshow is displaying temp3 on both figure(1) and figure(2), but I don't understand why this would be happening. What should I change to ensure that I get the behavior I want (both images have their proper titles and figure labels)? Here's the code:
figure(1)
imshow(mat2gray(temp2));
title('After background subtraction and image thresholding')
figure(2)
imshow(mat2gray(temp3)); hold on
title('After peak detection')
scatter(good(1:no_good, 2), good(1:no_good, 1), 60, 'red')
impixelinfo;
hold off;
3 Comments
Sivani Pentapati
on 28 Sep 2021
Edited: Sivani Pentapati
on 28 Sep 2021
The code which you have provided seems to be working fine, with images being displayed in their respective windows. Please re-check the assignment into "temp2" and "temp3", as that might result in same image being displayed in the two windows. Please refer to the documentation of figure for more information. If the above workaround doesn't solve your problem, could you please provide a detailed explanation of what is expected from the code so that we can replicate the issue.
Lakshay Sood
on 28 Sep 2021
Edited: Lakshay Sood
on 28 Sep 2021
Kevin Holly
on 29 Sep 2021
I'm not sure why you are having an issue. You can name your figures if that will help you resolve the issue.
fh1 = figure('Name','Window 1')
imshow(mat2gray(temp2));
title('After background subtraction and image thresholding')
fh2 = figure('Name','Window 2')
imshow(mat2gray(temp3)); hold on
title('After peak detection')
scatter(good(1:no_good, 2), good(1:no_good, 1), 60, 'red')
impixelinfo;
hold off;
Are you selecting or moving the figures manually before running commands or are you running all the command at once?
In the code given, there is no instance of you using imshow for temp1 or temp4.
Answers (1)
yanqi liu
on 29 Sep 2021
figure('Name', 'demo1', 'NumberTitle', 'off')
imshow(mat2gray(temp2));
title('After background subtraction and image thresholding')
figure('Name', 'demo2', 'NumberTitle', 'off')
imshow(mat2gray(temp3)); hold on
title('After peak detection')
scatter(good(1:no_good, 2), good(1:no_good, 1), 60, 'red')
impixelinfo;
hold off;
Categories
Find more on Display Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!