Added matlab binarization file

This commit is contained in:
2023-02-05 20:38:18 +04:00
parent f4211f8b7b
commit 4c4b83c9ca
2 changed files with 108 additions and 0 deletions

26
binarization/binarizer.m Normal file
View File

@@ -0,0 +1,26 @@
function out_im = binarizer(in_im, v, h)
%This programs splits an image into 'v' blocks in vertical direction
% and into 'h' blocks in horizontal direction. All the bloacks are equal.
[x, y] = size(in_im); %size of the input image
out_im = []; %output image
for ii = 1:(v)
temp = [];
ranx = ((ii-1)*ceil(x/v)+1):(ii*ceil(x/v)); %horizontal range
if ii == v
ranx = (((ii-1)*ceil(x/v)+1):x);
end
for jj = 1:(h)
rany = ((jj-1)*ceil(y/h)+1):(jj*ceil(y/h)); %horizontal range
if jj == h
rany = (((jj-1)*ceil(y/h)+1):y);
end
t = graythresh(in_im(ranx,rany));
temp = cat(2,temp,imbinarize(in_im(ranx,rany),t));
end
out_im = cat(1,out_im,temp);
end
end