How to calculate the number of grid on the image whose having the outline of the image
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SWAMINATHAN
am 2 Sep. 2015
Kommentiert: SWAMINATHAN
am 29 Okt. 2015
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148656/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148658/image.jpeg)
7 Kommentare
Image Analyst
am 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.
Akzeptierte Antwort
Guillaume
am 16 Sep. 2015
Bearbeitet: Guillaume
am 16 Sep. 2015
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 Kommentare
Weitere Antworten (1)
Walter Roberson
am 4 Sep. 2015
Bearbeitet: Walter Roberson
am 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 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!