# selecting bricks from image

I have an image of bricks of different sizes. What I want to do is when I click on the corner of the brick it should mark the lines around the brick. Can anyone please help me how can I do that... here is the image

• I have tried using Sobel and canny edge but its not so sucessful Commented Oct 29, 2015 at 5:40
• Please explain the reason before doing down vote Commented Oct 29, 2015 at 5:46

Let me suggest a simple solution , however if you want to go for a more robust solution let me know.

So first I would look for a way to enhance the signal. In my experience red objects appear even stronger if you look at red-green

diff = im(:,:,1) - im(:,:,2);
figure;imshow(diff,[]);


Than I would use simple thresholding (choose threshold value manually ) to get a blackwhite image. To make it more robust I would use some morphology operations like opening and filling. (If you dont know what that is I would look at matlab help. Than finally you can select the brick with bwselect and take its perimeter with bwpeim.

Viola:

diff = im(:,:,1) - im(:,:,2) ;
bw = diff > 35;
bw = imopen( bw , ones(1,5) );
bw = imopen( bw , ones(5,1) );
bw = imfill(bw , 'holes');
brick = bwselect(bw);
brick = bwperim(brick);


and you can see a simple output here: Please note that this is quite specific for this image but that's a good simple way to get you started.

• Yes it helped me a lot to get close to what I expect. But I want to know that if I have 'x' and 'y' points of the brick than how can I select using bwselect? Commented Oct 30, 2015 at 12:45

I think you don't need to find the edges in this specific case. I order to select a brick you need to have some kind of representation such as, making whole brick'white or 1' and the gaps between two brick 'black/ 0'.

I processed the given image by first converting to RGB to BW and then adjust the contrast. After then I tried to make the new image as I mentioned above by viewing the pixel values. example code is attached ;

I hope other people in this group may help you better than me.

BR FF

Code for the above figure;

for i=1:2112  % (image rows)
for j=1:2816  % (image cols)