how to plot 120 images on same figure by using loops
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Suppose i need to loop the output of 120 images and show it on a figure
But in the code below it shows on separate figures:
%Load the folder in which input images exists
myfile=dir('E:\dataset\Input_images\*.jpg');
%Counts the number of files
numFiles = length(myfile)
numRows = ceil(sqrt(numFiles))
%Load the folder in which ground truth images exists
myfile1=dir('E:\dataset\GT\*.png');
%Counts the number of files
numFiles1 = length(myfile1)
numRows1 = ceil(sqrt(numFiles1))
for k = 1 : numFiles
for j = 1 : numFiles1
thisFileName = fullfile(myfile(k).folder, myfile(k).name);
thisImage = imread(thisFileName);
grey=rgb2gray(thisImage);
thisFileName1 = fullfile(myfile1(k).folder, myfile1(k).name);
thisImage1 = imread(thisFileName1);
if (numRows == numRows1)
%Segmentation of the image
seg = imsubtract(thisImage1,grey);
figure;
subplot(2,4,k);
imshow(seg);
drawnow;
end
end
end
0 Kommentare
Antworten (2)
Image Analyst
am 31 Mär. 2019
Use
plotCount = 1
for k = 1 : numFiles
for j = 1 : numFiles1
subplot(12, 10, plotCount);
plotCount = plotCount + 1;
imshow(............
etc.
Don't use figure() anywhere in that code to create a new figure.
0 Kommentare
Adam Danz
am 26 Mär. 2019
You're creating a new figure upon each iteration. I haven't sifted through all of your code and I'm not sure how 120 images are going to be placed on one figure. But the solution will be to move the call to figure() outside of the loops if you're only creating one figure. It looks like there will only be 8 subplots so I'm still not sure how you're organizing the 120 images on the same figure.
figure(); % <--- create figure outside of loop
for k = 1 : numFiles
for j = 1 : numFiles1
% ignoring bulk of code
if (numRows == numRows1)
%Segmentation of the image
seg = imsubtract(thisImage1,grey);
%figure; % <---- remove this
subplot(2,4,k);
imshow(seg);
drawnow;
end
end
end
4 Kommentare
Adam Danz
am 1 Apr. 2019
"But i want to get all these segmented 120 images of output on the same figure and not on different figures."
I assum you want them tiled and displayed in a grid (rather than overlaying them all with transparency).
Matlab's subplot function produces a grid of subplots but with large margins. Squeezing 120 subplots onto one figure will result in tiny subplots.
Instead, I recommend using this FEX submission. tight_subplot() which allows you to more easily control the margin space.
Here's an example that produces a [12 x 10] grid of subplots with vertical and horizontal spacing of 0.005 (normalized units), bottom margin on 0.01, top margin 0.1, and left & right margins 0.01.
h = tight_subplot(12, 10, [.005, .005], [.01, .1], [.01, .01]);
for i = 1:120 % or i = 1:length(h)
imshow(image, 'Parent', h(i)); %specify axis handle
end
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!