Subplot images from database folder using index value.

조회 수: 1 (최근 30일)
Simo Calandra
Simo Calandra 2019년 12월 11일
답변: Image Analyst 2019년 12월 11일
Hello, I have this code which out put returns 10 filenames corresponding to 10 images I have in my folder. How I can I change the code so that instead of a list to the related filenames (relation is to v=similarity value for each image and i=index for corresponding file name) in the same sorted order, I get the 10 corresponding images into 1 figure/subplot ? I am learning and still finding difficulit to connect all the dots.

답변 (2개)

Image Analyst
Image Analyst 2019년 12월 11일
I don't understand the question, but to sort by decreasing values of r, read in the image for each r, and display the image, for 10 images, you can do
% Get the filenames somehow....
files = dir('*.png');
filenames = {files.name}
% Get r somehow... whatever method you have...
r = rand(1, length(files));
% Sort the r variable.
[sorted_r, sortOrder] = sort(r(:), 'descend');
% Now sort filenames the same way as r was sorted. filenames should already exist by this line.
filenames = filenames(sortOrder);
% Now display the first 10
hFig = figure;
for k = 1 : min([length(filenames), 10])
subplot(3, 4, k);
thisImage = imread(filenames{k});
imshow(thisImage);
caption = sprintf('Image %d: "%s"\nr = %.3f', ...
k, filenames{k}, sorted_r(k));
title(caption, 'FontSize', 12);
axis('on', 'image');
drawnow;
end
hFig.WindowState = 'maximized'; % Requires fairly recent version of MATLAB.

Image Analyst
Image Analyst 2019년 12월 11일
Regarding your edited question (where you took out mention of the "r" variable over which you wished to sort), you might want to look at the montage() or imtile() functions.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by