threshold images and save as jpeg in loop

4 次查看(过去 30 天)
Hi, I would like to run a threshold to approx 50 images of mine and then save the output as jpg, currently im not managing as the saved file says it cannot be read. below is my code
for i = 1:numel(I)
%Obtain red matrix of image
filename = fullfile(path, I(i).name);
im = imread(filename);
%Extract Red Channel
b = im(:,:,1);
%Normalising red values
Norm=double(b(:))./255;
%Reshaping to fit image shape
[f,g]=size(b);
imn=reshape(Norm,[f,g]);
%threshold image
thresh = imn .* imn>(0.6258);
thresh_im = uint8(thresh);
name = int2str(i);
save([name, '.jpg'], 'thresh_im')
end
Please help?

采纳的回答

Subhadeep Koley
Subhadeep Koley 2020-2-13
Use imwrite instead of save.
for i = 1:numel(I)
% Obtain red matrix of image
filename = fullfile(path, I(i).name);
im = imread(filename);
% Extract Red Channel
b = im(:, :, 1);
% Normalising red values
Norm = double(b(:)) ./ 255;
% Reshaping to fit image shape
[f, g] = size(b);
imn = imresize(Norm, [f, g]);
% Threshold image
thresh = imn .* imn>(0.6258);
thresh_im = uint8(thresh);
% Save the image
imwrite(thresh_im, ['img', num2str(i), '.jpg']);
end

更多回答(0 个)

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by