how to display an image

조회 수: 3 (최근 30일)
Blazej Staniak
Blazej Staniak 2021년 11월 30일
답변: yanqi liu 2021년 12월 1일
Hello, i have a part of a program that recognizes my letters, everything looks nice the program recognized. But I have such a problem, I would like to show it in the program. After doing this, how do you present it in the form as in the attachment. I am pasting the code below
for n= 1: length(propied)
BBs= propied(n).BoundingBox;
subImage= imresize(imcrop(im, BBs), [150 80]);
baseFileName = sprintf('Obraz #%d.png', n);
fullFileName = fullfile(string(newSubFolder(1)), baseFileName);
imwrite(~subImage, fullFileName);
hold on;
subplot (1, 8, n);
set(gcf, 'Position', get(0,'Screensize'));
figure(11), imshow(subImage);
end
close all;

답변 (3개)

Spectro
Spectro 2021년 11월 30일
What about using just tiledlayout? See the attachment (code below).
M = ones(400, 200);
tiledlayout(1, 6, 'TileSpacing', 'tight')
nexttile;imshow(M)
nexttile;imshow(M)
nexttile;imshow(M)
nexttile;imshow(M)
nexttile;imshow(M)
nexttile;imshow(M)

Image Analyst
Image Analyst 2021년 12월 1일
Looks like it should work, though I'd pull figure(11) outside the loop and put it before the loop. Did it now work like you expected? This is how I'd do it (untested):
% Create a new figure called hFig.
hFig = figure();
numDigits = length(propied);
for n = 1 : numDigits
% Crop out this digit from the larger image and resize it to 150 rows by 80 columns.
BBs = propied(n).BoundingBox;
subImage = imresize(imcrop(im, BBs), [150, 80]);
% Display this subimage in its own axes.
subplot (1, numDigits, n);
imshow(subImage);
% Create a filename and save the subimage to its own disk file.
baseFileName = sprintf('Obraz #%d.png', n);
fullFileName = fullfile(string(newSubFolder(1)), baseFileName);
imwrite(~subImage, fullFileName);
end
g = gcf;
g.WindowState = 'maximized';
% Ask user if they want to close the figure.
promptMessage = sprintf('Do you want to close the figure now?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Yes', 'No - leave it up', 'Yes');
if contains(buttonText, 'Yes', 'IgnoreCase', true)
% They want to close it.
close(hFig);
end

yanqi liu
yanqi liu 2021년 12월 1일
yes,sir,may be use
figure(11); clf;
set(gcf, 'Position', get(0,'Screensize'));
for n= 1: length(propied)
BBs= propied(n).BoundingBox;
subImage= imresize(imcrop(im, BBs), [150 80]);
baseFileName = sprintf('Obraz #%d.png', n);
fullFileName = fullfile(string(newSubFolder(1)), baseFileName);
imwrite(~subImage, fullFileName);
figure(11);
subplot (1, 8, n);
imshow(subImage, []);
end

Community Treasure Hunt

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

Start Hunting!

Translated by