Ok, I figured it out after few trials..I reply to myself!
The code is rough, but could be usefull to somenoe else. Cheers
%%%%%%%
im = imread(binaryimage);
%%in my case, image is 1444x806
% blockRows = 26; % Rows in block.
% blockColumns = 38; % Columns in block.
%% divide the image with blocks size 26x38 >> divide the image in (806/26)31 rows x (1440/38)38 colmns
Mcell = mat2cell(im,[26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26],[38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38]);
%% for every cell,count how many black and how many white pixels >> two arrays cointaining the numbers
a=zeros(31,38);
b=zeros(31,38);
c=zeros(31,38);
d=zeros(31,38);
for i=1:31
for j=1:38
index = find(Mcell{i,j}==0);
a(i,j)=numel(index); % how many black pixels==0
b(i,j)=numel(Mcell{i,j})a(i,j); %how many whyte pixels==1
c(i,j)=((numel(Mcell{i,j})a(i,j))./988).*100; %percentage of white pixels
end
end
%imshow(im),impixelinfo
%% display the grid
im(26:26:end,:,:) = 70; %# Change every tenth row to black
im(:,38:38:end,:) = 70; %# Change every tenth column to black
imshow(im); %# Display the image
%% operations in c array of percentages
for i=1:31
for j=1:38
index2=find(c(i,j)<100 & c(i,j)>16); % condition to satisfy
d(i,j)=numel(index2); % matrix with =1 when satisfied
end
end
c(~d)=0;
[row,col] = find(c>0); %indexes in which c>0
f=[row col]; %elemnts that identify cells to analyse
for x=1:numel(row)
figure
imshow(Mcell{f(x,1),f(x,2)})
end
