Saving images after binarizing them

6 views (last 30 days)
Hi all. I have this code:
Namelist = cell(length(filelist), 1);
invariants = zeros(length(filelist), 11); % change the number at the end to
% number of columns % 11 is 4th order. 6 is 3rd
for i = 1:length(filelist)
imagename = filelist(i).name;
Namelist{i, 1} = filelist(i).name;
I = imread ([path, '/', imagename]);
I = im2double (I);
I = 1-I;
I = imbinarize(I);
Due to issues with the end result, when I turn my image into 0s and 1s, I want to be able to save all of them into a separate folder so I can see what changing the threshold does to them. Is there a way to automatically save all the photos using imwrite() to an external file, but keeping the file names they have?
Example:
Original image name: 'Letter 9', 'Letter g', 'Letter x'
after binarize I want to save them again using the same name.
Thank you!

Accepted Answer

Image Analyst
Image Analyst on 2 Jul 2019
Don't use path as a variable name - it's the name of a built-in function.
Just specify a different output folder, like "Binary images":
outputFolder = fullfile(filelist(i).folder, 'Binary Images');
outputFileName = fullfile(outputFolder, imagename);
imwrite(I, outputFileName);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!