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

2 ビュー (過去 30 日間)
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 件のコメント
Image Analyst
Image Analyst 2015 年 9 月 14 日
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 2015 年 9 月 15 日
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.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2015 年 9 月 16 日
編集済み: Guillaume 2015 年 9 月 16 日
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 件のコメント
SWAMINATHAN
SWAMINATHAN 2015 年 10 月 29 日
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 2015 年 10 月 29 日
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

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 9 月 4 日
編集済み: Walter Roberson 2015 年 9 月 4 日
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 件のコメント
SWAMINATHAN
SWAMINATHAN 2015 年 9 月 21 日
To Image Analyst sir ,my grid start in the first line and the grid spacing is 25 pixels.
SWAMINATHAN
SWAMINATHAN 2015 年 9 月 21 日
編集済み: Walter Roberson 2015 年 9 月 21 日
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

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by