how to plot multiple images (separately) in one window

조회 수: 23 (최근 30일)
Fatma Nur Disci
Fatma Nur Disci 2020년 12월 29일
댓글: Adam Danz 2020년 12월 30일
Hi everyone,
I have 2304x1024 matrix. I assume that each 3 rows of this matrix describe an image.(so I have 768 images and each image size = 3x1024 ).
Let's assume that imagesc(1:3, 1024 ) gives the first image, imagesc(4:6,1024) describes the second one and so on.
My code is here :
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
imagesc(data); %%%% or pcolor(data) or %%%% I = mat2gray(data) and imshow(I)
end
When I use plot instead of imagesc I can plot multiple graphs in one figure :
figure
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
subplot(1,768,ind);
plot(data);
hold on;
end
I want to display images not graphs.
How to plot multiple images side by side in 1x768 format in a figure for example ? Or 32x24 format in a figure?
Thanks for your help.
  댓글 수: 2
Image Analyst
Image Analyst 2020년 12월 30일
편집: Image Analyst 2020년 12월 30일
You aren't really going to display 768 images side by side across your display are you? Each image or plot would be only a pixel or two wide! Even if you did
subplot(28, 28, ind);
they'd still be pretty tiny!
If your screen is in a 9x16 aspect ratio, you can say (9*r) * (16*r) = 768, or r=2.3 and your subplot would look like
subplot(21, 37, ind);
Adam Danz
Adam Danz 2020년 12월 30일
...or use tiledlayout('flow') and let Matlab arrange the plots for you. But even that has problems as I illustrated in my answer.

댓글을 달려면 로그인하십시오.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 29일
편집: KALYAN ACHARJYA 2020년 12월 29일
"How to plot multiple images side by side in 1x768 format in a figure for example?"
I assumed that you want to divide the data into several subsections. Plots display data in the same axes, while imageshows or images can display with a concatenation (horizontal or vertical). Although you can arrange 2D individual planes in a 3D vector.
If plots multiple subdivisions from image or matrix data, in this case you can follow-
1st way: If you are looking for plot sections of the data matrix differently, you have follow the following ways, please set the subplot subwindows number accordingly
data=randi([0,255],[2304,1024]);
data_blocks=mat2cell(data,3*ones(1,768),1024);
for i=1:length(data_blocks)
subplot(6,128,i), imagesc(data_blocks{i})
end
2nd way: Directly access the indices using loop
data=randi([0,255],[2304,1024]);
for i=1:3:2304
subplot(....),imagesc(data(i:i+2,:))
end
Note: Please note on the large numbers of figures/plots
  댓글 수: 3
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 29일
"I have 2304x1024 matrix. I assume that each 3 rows of this matrix describe an image.(so I have 768 images and each image size = 3x1024 )."
You can set the tile layout (subplot) as per total window display, please do the changes as per requirements
6x128=768, see the subplot function
If you are using MATLAB version 2019b or latest, you can use title function
https://www.mathworks.com/help/matlab/ref/tiledlayout.html
Fatma Nur Disci
Fatma Nur Disci 2020년 12월 30일
Thanks ! Yesterday I plotted all images just adding my code "subplot" before imagesc :
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
subplot(32,24,ind)
imagesc(data); %%%% or pcolor(data) or %%%% I = mat2gray(data) and imshow(I)
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam Danz
Adam Danz 2020년 12월 29일
768 independent axes on a figure will likely be problematicm, specifically the memory needed and the tiny size of each axis.
To demonstrate, the code below creates all 768 axes but I had to stop it after 551 axes because it was taking too long to add another axes (scroll down for more advice).
wholedata = rand(2304,1024);
nImages = size(wholedata,1)/3;
assert(mod(nImages,1)==0, 'The number of rows of data does not agree with number of images.')
data3D = reshape(wholedata',size(wholedata,2),3,[]);
fig = figure();
tlo = tiledlayout(fig,'flow','TileSpacing','compact','Padding','compact');
for i = 1:size(data3D,3)
ax = nexttile(tlo);
imagesc(ax,data3D(:,:,i)')
end
Why not keep your image data together in its original 2304x1024 array?
figure()
imagesc(wholedata)
If you want to show the border between every 3rd row,
h=arrayfun(@(y)yline(y,'w-'),.5:3:size(data,1));
but that will add a lot of lines to the image.
  댓글 수: 2
Fatma Nur Disci
Fatma Nur Disci 2020년 12월 30일
Thanks ! Yesterday I plotted all images using figure and subplot before imagesc :
for ind=1:768
start= (ind-1)*3+1;
stop=ind*3;
data = wholedata(start:stop,:);
subplot(32,24,ind)
imagesc(data); %%%% or pcolor(data) or %%%% I = mat2gray(data) and imshow(I)
end
Adam Danz
Adam Danz 2020년 12월 30일
I'm curious to see a screenshot of this figure, if you're willing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by