How do I Plot images in two different figures

9 Ansichten (letzte 30 Tage)
Emmanuel
Emmanuel am 14 Mär. 2017
Kommentiert: Jan am 15 Mär. 2017
In this snippet below, I want subplot 1 and 2 as a part of the same figure, which is something I am to get. I need a separate plot figure of the "%Separate side figure". I am not able to obtain that. Can you please help me out here?
Also, if I comment pause(0.000000001), my plot doesn't show up. Do you guys know why?
Thanks!
for i = 1 : length(srcFilesKinect)
axis off
filenameBL = strcat( path,'sk_left_rgb/',srcFilesBL(i).name);
I = imread(filenameBL); axis off
subplot(3,2,1), subimage(I) % Subplot 1
title( 'left')
filenameBR = strcat( path,'sk_right_rgb/',srcFilesBR(i).name);
I = imread(filenameBR); axis off
subplot(3,2,2), subimage(I) %Subplot 2
title('right')
filenameKinect = strcat( path2,srcFilesKinect(i).name);
I = imread(filenameKinect); %Separate side figure
%imshow(I);
%subplot(3,2,3), subimage(I)
image(I)
title('Demo')
fprintf('Reading %d th image\n',i)
pause(0.000000001)
end
  2 Kommentare
Jan
Jan am 14 Mär. 2017
Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging.
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
Emmanuel
Emmanuel am 14 Mär. 2017
Okay. Thank you for the suggestion

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Adam
Adam am 14 Mär. 2017
doc figure
Just create a figure explicitly (which you should always do anyway unless you are plotting on a GUI you have created), get its axes explicitly and plot on them explicitly. e.g.
hFig = figure; hAxes = gca;
imshow( hAxes, I );
  2 Kommentare
Emmanuel
Emmanuel am 14 Mär. 2017
Hey! Thanks I am getting this error:
Error using images.internal.imageDisplayParsePVPairs (line 125)
Invalid input arguments.
Error in images.internal.imageDisplayParseInputs (line 69)
[common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});
Error in imshow (line 223)
[common_args,specific_args] = ...
Error in dataSequenceEdit (line 63)
imshow( hAxes, I );
Do you know why?
Adam
Adam am 15 Mär. 2017
Ah, sorry, I didn't check and thought all plotting functions had this syntax now - I never use imshow myself. Apparently imshow is still archaic so you need to use
imshow( I, 'Parent', hAxes );

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 14 Mär. 2017
Bearbeitet: Jan am 14 Mär. 2017
The pause is required to allow Matlab to update the graphics. The minimal delay is 0.01, so pause(0.000000001) does the same as pause(0.01). I'd prefer drawnow for the updating, but both work reliably.
subimage is deprecated, prefer imshow.
Do not use "path" as the name of a variable, because this shadows an important Matlab function. This can cause a very strange behavior during debugging. I've renamed to to "path1".
Prefer fullfile instead of strcat to concatenate file names, because it cares about the separators.
Then:
Axes1H = subplot(3,2,1);
title('left');
Axes2H = subplot(3,2,2);
title('right');
Fig2H = figure;
Axes3H = axes;
title('Demo');
for i = 1 : length(srcFilesKinect)
filenameBL = fullfile(path1, 'sk_left_rgb', srcFilesBL(i).name);
I = imread(filenameBL);
imshow(I, 'Parent', Axes1H);
axis off
filenameBR = fullfile(path1, 'sk_right_rgb', srcFilesBR(i).name);
I = imread(filenameBR);
imshow(I, 'Parent', Axes2H)
axis off
filenameKinect = fullfile(path2, srcFilesKinect(i).name);
I = imread(filenameKinect);
imshow(I, 'Parent', Axes3H);
axis off
fprintf('Reading %d th image\n', i);
drawnow;
end
There will be better names than the counted "Axes1H", something more meaningful. Indices inside names of variables are a bad idea.
  2 Kommentare
Emmanuel
Emmanuel am 14 Mär. 2017
Thank you! I am getting this error though:
Error using imshow>validateParent (line 348)
HAX must be a valid axes handle.
Error in imshow (line 253)
validateParent(specific_args.Parent)
Error in dataSequenceEdit (line 62)
imshow(I, 'Parent', Axes3H);
Do you know why?
Jan
Jan am 15 Mär. 2017
After
Fig2H = figure;
Axes3H = axes;
Axes3H is a valid axes handle. It can only get invalid, if this axes is deleted, e.g. by clf or a similar command, or if its figure is deleted.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by