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 enter image description here

  • $\begingroup$ I have tried using Sobel and canny edge but its not so sucessful $\endgroup$ – Aadnan Farooq A Oct 29 '15 at 5:40
  • $\begingroup$ Please explain the reason before doing down vote $\endgroup$ – Aadnan Farooq A Oct 29 '15 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);

enter image description here

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.


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. enter image description here

  • $\begingroup$ 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? $\endgroup$ – Aadnan Farooq A Oct 30 '15 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.


Image contrast


Code for the above figure;

for i=1:2112  % (image rows)
    for j=1:2816  % (image cols)
        if contrastAdjusted(i,j) < 110
            ff(i,j) = 1;
            ff(i,j) = 0;
  • $\begingroup$ Please anyone can help me further $\endgroup$ – Aadnan Farooq A Oct 29 '15 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.