Brick wall

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
alduin
Posts: 2
Joined: 2016-01-07T14:37:13-07:00
Authentication code: 1151

Brick wall

Post by alduin » 2016-01-07T14:40:23-07:00

I have a photo from which I'd like to extract the lines from the bricks.

http://i.imgur.com/xyyu4f8.jpg

I tried using Canny edge and hough lines without much success... Any advices?

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Brick wall

Post by fmw42 » 2016-01-07T20:13:39-07:00

Your brick and mortar pattern is too "noisy" or rough to get much from any edge operator and the lines are not long and straight enough for Hough lines. So I guess you are "up against a brick wall" in solving this. :wink: Sorry, I could not resist the pun.

Best I can suggest is converting to white lines on black background, then scaling down to 1 column and then back up to the original size. Then thresholding and applying morphology thinning.

Code: Select all

convert xyyu4f8.jpg \
-fuzz 25% -fill black -opaque "#FA0000" \
-fill white +opaque black \
-scale 1x! -scale 94x294! \
-threshold 50% \
-morphology Thinning:-1 Skeleton \
result.png

alduin
Posts: 2
Joined: 2016-01-07T14:37:13-07:00
Authentication code: 1151

Re: Brick wall

Post by alduin » 2016-01-08T09:04:16-07:00

Nice pun!

This is great, I've tried the conversion you suggested and It's beyond my expecatation.


I just need to find a way to get the Vertical lines, any suggestions?

User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Brick wall

Post by GeeMack » 2016-01-08T11:33:37-07:00

alduin wrote:I have a photo from which I'd like to extract the lines from the bricks.
As fmw42 said, the original image is pretty poorly defined, so there's not much that can be done with it. If you want to isolate the mortar lines you could try changing it to just two shades of gray, force those to just black and white, and make the black transparent. Some tweaking of the brightness (-modulate 80) before reducing the number of colors might help bring out more of what you want, but probably not by much. Roughly something like this...

Code: Select all

convert xyyu4f8.jpg -background none -colorspace gray -modulate 80 -colors 2 -normalize -transparent black result.png
Or depending on what you're trying to achieve, maybe starting from scratch would be a better approach. :wink:

Code: Select all

convert -background none -size 48x192 tile:pattern:bricks -negate -scale 300%x200% -transparent black result.png

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Brick wall

Post by fmw42 » 2016-01-08T11:35:41-07:00

The verticals are probably not long enough nor lined up well, but you can try scaling to one row rather than one column.

Code: Select all

convert xyyu4f8.jpg \
-fuzz 25% -fill black -opaque "#FA0000" \
-fill white +opaque black \
-scale x1! -scale 94x294! \
-threshold 50% \
-morphology Thinning:-1 Skeleton \
result.png
When I try that, I get only one vertical line.

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Brick wall

Post by fmw42 » 2016-01-08T11:44:24-07:00

You can also do the following, but it will just show how rough the mortar is.

Code: Select all

convert xyyu4f8.jpg \
-fuzz 25% -fill black -opaque "#FA0000" \
-fill white +opaque black result.png

Post Reply