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
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.
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);
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.
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; else ff(i,j) = 0; end end end imshow(ff);