mardi 3 mars 2015

Matlab - Dinamic Thresholding

I am trying to make a dinamic thresholding, but It is appearing some errors. I am trying to adapt from this code: http://ift.tt/1vYPs7k



function [Output ] = dinamicthresh()

[filename,pathname] = uigetfile('*.bmp; *.jpg', 'Please select an image file');


I=fullfile (pathname,filename);


I=imread(I);


I=rgb2gray(I);


I=im2double(I);

[H,W]= size(I);
Output= zeros(H,W);

halfH=round(H/2);
halfW=round(W/2);

for i= H:H
for j = W:W
C = I(i-halfH:i+halfH,j-halfW:j+halfW);
adaptative_thresh = mean(mean(C)) - 12;
if I(i,j) < adaptative_thresh
Output(i,j)= 1;
else
Output(i,j)= 0;
end
end
end

subplot(1,2,1);imshow(I);title('Original Image');
subplot(1,2,2);imshow(Output);title('Adaptive Thresholding');

end

Aucun commentaire:

Enregistrer un commentaire