フィルターのクリア

How do I save image in folder using imrite and how do I show all the image in folder?

1 回表示 (過去 30 日間)
Here my codes:-
%Save the folder of images in the current directory
path_directory='/home/motmot/Documents/Malignant/M1/Testing/benign/validate_image/b245'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']);
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
image_orginal=imread(filename);
img=im2double(image_original);
[r,c,b]=size(img);
data=reshape(img,r*c,b);
[ctr, class]=fcm(data,2);
disp(ctr);
class1=reshape(class(2,:),r,c);
imshow(class1);
imwrite(class1,'fcmgrayb245_73_864_rap00001.jpg');
end

採用された回答

Image Analyst
Image Analyst 2022 年 10 月 16 日
If the images are not showing, except for the last one. Put a drawnow right after you call imshow.
imshow(class1);
drawnow;
This will force the images to update on the screen immediately. Otherwise if your loop is too fast, maybe only the last one is shown.

その他の回答 (1 件)

Jan
Jan 2022 年 10 月 15 日
Maybe you want to create the file name dynamically:
...
outFile = fullfile(path_directory, sprintf('fcmgrayb245_73_864_rap%05d.jpg', k));
imwrite(class1, outFile);
  2 件のコメント
Dayangku Nur Faizah Pengiran Mohamad
Dayangku Nur Faizah Pengiran Mohamad 2022 年 10 月 16 日
Ok thanks. But I want to ask, about this code:-
outFile = fullfile(path_directory, sprintf('fcmgrayb245_73_864_rap%05d.jpg', k));
what is mean by the '%05d' from the last code? Is it 5 times repeating save the image?
Jan
Jan 2022 年 10 月 16 日
See: doc sprintf, or sprintf
The %05d appears in the sprintf command. Then it influences the output to a char vector and not the number of times of saving. Try this:
sprintf('%05d', 17)
ans = '00017'
sprintf('%5d', 17)
ans = ' 17'
sprintf('%d', 17)
ans = '17'
The %5d reserves 5 characters. With %05d the leading characters are filled by zeros.
"fcmgrayb245_73_864_rap00001.jpg" looked like you want to append a counter at the end of the file name.

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by