threshold images and save as jpeg in loop

조회 수: 1 (최근 30일)
udi ibgui
udi ibgui 2020년 2월 13일
답변: Subhadeep Koley 2020년 2월 13일
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