image_folder = 'F:\kuliah\semester6\TA2\mencoba';
outfolder = 'F:\kuliah\semester6\TA2\mencoba\hasil';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
fileinfo = dir(fullfile(image_folder, '*.jpg'));
filenames = fullfile({fileinfo.folder}, {fileinfo.name});
total_images = numel(filenames);
for n = 1 : total_images
thisfile = filenames{n};
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfile);
V = squeeze(citra);
fprintf('processing %s\n', basename);
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, [basename 'coba' ext]);
saveas(citra3, outfile);
end
A folder containing many images has been read, but only one output is stored. I have been helped by Mr.Walter Roberson, but I still can't solve the problem of how to save multiple images from the output of the matlab process.

댓글 수: 2

Rik
Rik 2021년 2월 24일
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
Frisda Sianipar
Frisda Sianipar 2021년 2월 24일
I'm sorry, thankyou

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

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 2월 24일

0 개 추천

You simply have to generate a sequence of unique filenames to save to. Something like this:
outfile = fullfile(outfolder, sprintf('%s-coba-%03d.%s',basename,n,ext]);
saveas(citra3, outfile);
That way you'll generate filenames of the type: basename-coba-001.ext - I replaced the whitespaces in the filename with '-', because I prefer to have dashes instead, you can switch back. The %03d is just to give you zero-padded numbers incrementing with your loop-variable n.
HTH

댓글 수: 9

Frisda Sianipar
Frisda Sianipar 2021년 2월 24일
i try but still same. one image is stored, even though there are 2 processed images.
That is most likely due to the way you extracts the image-file-names:
fileinfo = dir(fullfile(image_folder, '*.jpg'));
filenames = fullfile({fileinfo.folder}, {fileinfo.name});
This in my opinion becomes rather complex to handle with combining different information from different cells to generate filenames.
When I do this I typically do:
files = dir(fullfile(image_folder, '*.jpg'));
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
citra = imread(thisfilename);
% etc
end
Rik
Rik 2021년 2월 24일
Based on the code you posted in your question, the processed images should be in that hasil folder. Also, none of the files in that folder could be from the code Bjorn posted. If you change code, please post what you did.
Frisda Sianipar
Frisda Sianipar 2021년 2월 24일
편집: Rik 2021년 2월 24일
it is have an error, could you help me?
Rik
Rik 2021년 2월 24일
You were the one who commented out the line where the basename variable was created. You should make sure you create it again.
You have to start reading the error-messages. It says that you have no function or variable basename. In your current version you have cut out the line:
[~, basename, ext] = fileparts(image_folder);
That was where you created that variable. Now you have to think about what you want for that variable in your current version.
Only you can decide that.
Frisda Sianipar
Frisda Sianipar 2021년 2월 24일
편집: Rik 2021년 2월 24일
sorry if it's a hassle, this is my first time using matlab
Undefined function or variable 'n'.
Rik
Rik 2021년 2월 24일
편집: Rik 2021년 2월 24일
Think about your code. What are you doing and why? Have you read the documentation for the functions you are using?
If you read the latest error message: "Undefined function or variable 'n'." Can you see where you define n? What was that line doing? What was the reason you commented it?
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
Also, feel free to put multiple things in 1 comment, instead of letting me merge your comments.
Frisda Sianipar
Frisda Sianipar 2021년 2월 24일
Thankyouu for the answer

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by