writing title on images

216 ビュー (過去 30 日間)
Mohanned Al Gharawi
Mohanned Al Gharawi 2018 年 12 月 20 日
コメント済み: Mohanned Al Gharawi 2018 年 12 月 20 日
Hello everybody,
I have 100 images, what my code does is reading the image and shows them, but I need to write a title on each image through the showing. When I run my code, the images begin showning but there is no titl on them just on the last one. What I need is showing the images in sequence and the title one them.
srcFiles = dir('F:\the source\*.mim');
for i = 1 : length(srcFiles)
filename = strcat('F:\the source\',srcFiles(i).name);
S{i} = double(imread(filename));
n=n+1;
end
for j=1:n
imshow(S{j},[]);
D{j} = imcrop(S{j},[35 1 260 240]);
imshow(D{j},[])
title(j);
end
Thanks
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 20 日
drawnow()

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 12 月 20 日
Try this for your second loop:
for k = 1 : length(S)
% Display the orginal image.
imshow(S{k}, []);
caption = sprintf('Original Image #%d out of %d', k, n);
title(caption, 'FontSize', 14);
drawnow;
pause(0.5); % Pause long enough for user to see image before it goes to the next one.
% Now crop the image and display it.
D{k} = imcrop(S{k}, [35, 1, 260, 240]);
imshow(D{k}, [])
caption = sprintf('Cropped Image #%d out of %d', k, n);
title(caption, 'FontSize', 14);
drawnow;
pause(1); % Pause long enough for user to see image before it goes to the next one.
end
but honestly, I don't know why you're doing this in two separeate loops and storing all the images (wasting memory) when you could do it all in one loop and use only one image by overwriting it every time.
  1 件のコメント
Mohanned Al Gharawi
Mohanned Al Gharawi 2018 年 12 月 20 日
Thank you it worked, Yes I agree with I should have done with one loop. Thanks again.

サインインしてコメントする。

その他の回答 (3 件)

madhan ravi
madhan ravi 2018 年 12 月 20 日
編集済み: madhan ravi 2018 年 12 月 20 日
A bold guess:
srcFiles = dir('F:\the source\*.mim');
S=cell(1,length(srcFiles));
for i = 1 : length(srcFiles)
filename = strcat('F:\the source\',srcFiles(i).name);
S{i} = double(imread(filename));
n=n+1;
end
D=cell(1,length(n));
for j=1:n
imshow(S{j},[]);
D{j} = imcrop(S{j},[35 1 260 240]);
figure
imshow(D{j},[])
title(j);
end

Mohanned Al Gharawi
Mohanned Al Gharawi 2018 年 12 月 20 日
Thanks for your respond,
The problem is still. The title is only written at the end of the loop. I mean the last image has only the title.

Walter Roberson
Walter Roberson 2018 年 12 月 20 日
projectdir = 'F:\the source';
srcFiles = dir( fullfile(projectdir, '*.mim') );
basenames = {srcFiles.name};
n = length(srcFiles);
S = cell(n, 1);
for i = 1 : n
filename = fullfile(projectdir, basenames{i})';
S{i} = im2double(imread(filename));
end
fig = figure();
cmap = colormap(gray(256));
ax = axes('Parent', fig);
D = cell(n, 1);
for j=1:n
D{j} = imcrop(S{j},[35 1 260 240]);
imagesc(ax, D{j});
colormap(ax, cmap);
title(ax, basenames{j});
drawnow();
end

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by