필터 지우기
필터 지우기

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

조회 수: 11 (최근 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