threshold images and save as jpeg in loop

4 vues (au cours des 30 derniers jours)
udi ibgui
udi ibgui le 13 Fév 2020
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?

Réponse acceptée

Subhadeep Koley
Subhadeep Koley le 13 Fév 2020
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

Plus de réponses (0)

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by