How to detect presence of an object in a image divided by gridlines?

2 views (last 30 days)
The image is 28*28 pixel and grid of 3*2 and bounding box is added and i need to get binary values as 1 if present and 0 if no object is present. So, here in this example i need to get the answer as an array of { 1 1 0 1 1 0 }
imagen=imread('g1.JPG0dim.jpg');
figure,subplot(3,3,1),imshow(imagen),title('Input Image');
imagen1=rgb2gray(imagen);
subplot(3,3,2),imshow(imagen1),title('Gray Image');
B=[0 1 0; 1 1 1; 0 1 0];
A2=imdilate(imagen1,B);
subplot(3,3,3),imshow(A2),title('Dilated Image');
A3=imerode(imagen1,B);
subplot(3,3,4),imshow(A3);title('Eroded Image');
A4=imsubtract(A2,A3);
subplot(3,3,5),imshow(A4);title('Subtracted Image');
threshold = graythresh(A4);
imagen2 =imbinarize(A4,threshold);
subplot(3,3,6),imshow(imagen2),title('Binary Image');
imagen3 = imfill(imagen2, 'holes');
subplot(3,3,7),imshow(imagen3),title('Holes Filled Binary Image');
imagen4 = bwareaopen(imagen3,15);
imagen5 = imagen4;
subplot(3,3,8),imshow(imagen5);title('Noise Reduced Image');
subplot(3,3,9),imshow(imagen5);title('Grid View ');
[rows, columns, numberOfColorChannels] = size(imagen5);
hold on;
for row = 0 : 10 : rows
line([0, columns], [row, row], 'Color', 'r');
end
for col = 14 : 28 : columns
line([col, col], [0, rows], 'Color', 'r');
end
L=bwlabel(imagen5);
propied=regionprops(L,'BoundingBox');
hold on
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
R1=imagen5(1:10, 1:14);
R4=imagen5(1:10, 15:28);
R2=imagen5(11:18, 1:14);
R5=imagen5(11:18, 15:28);
R3=imagen5(19:28, 1:14);
R6=imagen5(19:28, 15:28);

Answers (0)

Community Treasure Hunt

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

Start Hunting!