Hi, I'm a final year student at a university in Indonesia. Actually I tried reading the image in matlab and then applying certain operations like increasing contrast, removing background etc. Then I want to save the new image after the operation in a certain folder, but I face a problem in saving the image in matlab, the image is saved after only one operation while the image that has been read is more than one, then I want the saved image extension to be .jpg. please help me whoever knows the solution.
This is the coode:
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
files = dir(fullfile(image_folder, '*.jpg'));
% filenames = fullfile({fileinfo.folder}, {fileinfo.name});
% total_images = numel(filenames);
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
% for n = 1 : total_images
% thisfile = filenames{n};
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfilename);
V = squeeze(citra);
fprintf('processing %s\n', basename);
fig = figure;
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, sprintf(['%s-coba-%03d.%s',basename,'.jpg']));
saveas(citra3, outfile);
end

댓글 수: 5

outfile = fullfile(outfolder, sprintf(['%s-coba-%03d.%s',basename,'.jpg']));
your constant format ends in .%s and the content of the string is .jpg so you are going to end up with ..jpg
Frisda Sianipar
Frisda Sianipar 2021년 3월 1일
but the saved image extention is .fig sir
Frisda Sianipar
Frisda Sianipar 2021년 3월 1일
and images stored is only one sir while more than one processed image
Walter Roberson
Walter Roberson 2021년 3월 1일
you need to look inside the folder named hasil to find the images.
Frisda Sianipar
Frisda Sianipar 2021년 3월 1일
no result sir

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

 채택된 답변

Jan
Jan 2021년 3월 1일
편집: Jan 2021년 3월 2일

0 개 추천

Your code must fail with an error message in this line:
outfile = fullfile(outfolder, sprintf(['%s-coba-%03d.%s',basename,'.jpg']));
The SPRINTF command has 3 format specifiers, but no corresponding values. Maybe you mean:
outfile = fullfile(outfolder, sprintf('%s-coba-%03d.jpg', basename, iFiles));
% [EDITED] Typo fixed: iFile -> iFiles

댓글 수: 3

Frisda Sianipar
Frisda Sianipar 2021년 3월 1일
Error sir
They said "Undefined function or variable 'iFile'."
outfile = fullfile(outfolder, sprintf('%s-coba-%03d.jpg', basename, iFiles));
Frisda Sianipar
Frisda Sianipar 2021년 3월 2일
Thankyou sir, its work

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

추가 답변 (0개)

질문:

2021년 2월 28일

편집:

Jan
2021년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by