How to calculate the number of grid on the image whose having the outline of the image

3 views (last 30 days)
This is my input image, and my code is this ->
img = imread('tanjore3.png');
img(10:10:end,:,:) = 0;
img(:,10:10:end,:) = 0;
imshow(img);
i just place a grid on the image
now the partial output of this is shown below. My question is how to calculate the number of grid whose having the outline of the image ?
My output should be Example : OUTPUT=25 grids
  7 Comments
Image Analyst
Image Analyst on 14 Sep 2015
Don't be silly. OF COURSE the starting point of the grid lines has an effect. Just think about it. Just imagine that the whole grid was lowered a few pixels. Then the dip in the 8th grid column would show up in only one grid row, not two.
SWAMINATHAN
SWAMINATHAN on 15 Sep 2015
am very sorry sir if I irritated you or make you tense am a child since am very new to this domain and you are a master If i did anything wrong I apologise, please pardon me but dont punish.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 16 Sep 2015
Edited: Guillaume on 16 Sep 2015
This is something that is actually very easy to do with the new histcounts2 in 2015b:
img = im2bw(imread('one.png'));
[y, x] = find(~img); %find row and columns of each black pixel
%make sure the grid starts and end outside of the image for histcounts2 to work
gridx = 0 : 50 : size(img, 2)+50; %grid lines position
gridy = 0 : 50 : size(img, 1)+50; %grid lines position
gridcount = nnz(histcounts2(x, y, gridx, gridy))
The output of hiscounts2 (without the nnz) will actually tell you how many black pixels you have in each grid square
  4 Comments
SWAMINATHAN
SWAMINATHAN on 29 Oct 2015
Thank you very much sir , I will be grateful to you. your answer helped me a lot. I want to be stay in touch with you always sir. :-)
SWAMINATHAN
SWAMINATHAN on 29 Oct 2015
Sorry for very late reply sir. one more doubt sir. In Image and Video Processing am working in the area of Facial Expression Recognition and Emotion Detection. For experimental works I used viola jones algorithm for Face & Facial Components detection (Eye, Nose & Lips).
I am struggling in Localization i.e. locating the points on the Facial components. I used a manual method (ROI-Region of Interest) by clicking over an image it will retrieve the Pixel Position Point information.
I want to automate this Process as soon as I gave an input image the number of points localized as shown in the above Image should retrieve those pixel point information.
Please help me regarding this sir

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 4 Sep 2015
Edited: Walter Roberson on 4 Sep 2015
Let N be the interval between boundaries, in pixels. Then
black_line_detected = blockproc(YourImage, [N, N], @(block) ~all(block.data), 'PadMethod', 1);
detect_count = sum(black_line_detected(:));
  10 Comments
SWAMINATHAN
SWAMINATHAN on 21 Sep 2015
Edited: Walter Roberson on 21 Sep 2015
THIS IS THE CODE I WRITTEN TO COUNT THE GRID BUT ITS GIVING WRONG ANSWERS
A = imread('one.png');%# Load a sample 3-D RGB image
B = im2bw(A);%# Convert RGB image into Black & White
N = 25;%# N is the Grid Spacing
B(1:N:end,:,:) = 0;%# Change every Nth row to black
B(:,1:N:end,:) = 0;%# Change every Nth column to black
imshow(B);%# Display the image
impixelinfo();%# Display the Pixel information of the image
GridCount = 0;%# Initialise the Grid Count = 0
for i = (1:N:546)%# for (i = 1; i<end; i=i+25) where end = 246 the extreme end of x coordinate
for j = (1:N:292)%# for (j = 1; j<end; j=j+25) where end = 246 the extreme end of y coordinate
for x = (i:1:N)%# for (x = 1; x<=25; x++) where 25 is the Grid Spacing
for y = (j:1:N)%# for (y = 1; y<=25; y++) where 25 is the Grid Spacing
if((impixel(B,x,y) == 0))%# if image pixel information of that particular (x,y) coordinate is 0 then
GridCount = GridCount+1;%#Increase the GridCount by 1
end %# end if loop
end %# end y loop
end %# end x loop
end %# end j loop
end %# end i loop
disp(GridCount);%# Display the GridCount of the image

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!