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

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

It would be easier if you were to be able to specify the grid spacing as a number of pixels, instead of having to figure it out from the graph.
how to do that sir can you tell me in matlab coding
How are you numbering your grid? Do you want grid row and grid column, starting from the upper left? Or lower left?
Starting position is not a matter sir I need to calculate the total number of grid which have the temple's outline?
My blockproc() should do that, unless I made a typing mistake.
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.
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

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

Sir i Am currently working with matlab 2013b i dont have 2015b so please send the compatible code for 2013b
I HAD WRITTEN THE CODE LIKE THIS SIR 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
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. :-)
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)

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

Am very sorry sir till now I could not able to understand, can you send me the full code by the way you want to solve my problem.
YourImage = imread('tanjore3.png');
N = 25;
black_line_detected = blockproc(YourImage, [N, N], @(block) ~all(block.data), 'PadMethod', 1);
detect_count = sum(black_line_detected(:));
You asked for the number of grid areas, and detect_count is that number.
Sir I think you misunderstood the 25. I executed your code I got the result detected count = 1893. I dont know what is N=25? above you mentioned in that code. Sir I want the answer N=22 i.e the number of blocks (grid blocks) which having the temple outline is 22 which is = N. If I increased the grid blocks then the N value will become increased as i indicated as red numbers.
In future I will increase the grid size and again I will start count the number of grids like above mentioned in the red numbers
If this is an outline of a temple that you got by calling bwperim() or bwboundaries(), then you should have all the (x,y) coordinates of the image. That would make it SO much easier than dealing with an image that had black gridlines burned into it. Please attach a mat file with the list of outline coordinates. I'm sure you definitely have this.
This is my input image and the code given below
What is your grid spacing in pixels, and where does the first grid line start? For example, grid spacing is 50 pixels and the first grid line is at 1 so that grid #1 is at 1-50, grid #2 is 51-100, etc. Or does it start around 25 like you showed so grid #1 is 1-25, grid 2 is 26-75, grid 3 is 76-125, etc.?
The grid spacing is variable and it starts anywhere consistent. The poster is doing a kind feature analysis, refining the grid more each time and wanting to know the count at each step.
To Image Analyst sir ,my grid start in the first line and the grid spacing is 25 pixels.
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.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!