Page 1 of 1

achieve this effect

Posted: 2012-05-15T21:20:14-07:00
by mahadazad
Hi,
I have a sample image and I know it is achieved using ImageMagick. Can someone help achieving the same effect.

my image:
Image

desired effect:
Image

I tried to use morphology with close disk and also median parameters but the output was not like this.

Please help

Thank You

Re: achieve this effect

Posted: 2012-05-16T14:03:40-07:00
by mahadazad
somebody please help

Re: achieve this effect

Posted: 2012-05-16T14:34:09-07:00
by fmw42
I have tried but with little affect. Perhaps Anthony will have some better ideas using -morphology, this evening when he gets online. Perhaps he can come up with some kind of custom shape kernel that will simply erode corners into round shapes.

My best effort was:

convert otgd1y.png -blur 5x65000 -threshold 50% result.gif

But it is not converting square edges fully to round ones.

Edit:

Trying again, this seems to be better -- a large disk open morphology.

convert otgd1y.png -morphology open disk:8 result.gif

Image

Anthony can probably fine tune the disk radius. The disk radius probably needs to be some fraction of the thickness of the black lines. A radius of 8-10 works with 8 being 1/3 the black line thickness of 24. A radius of 12 which is 1/2 of the thickness of 24 does not work well as it broadens too much together. A thickness of 6 which is about 1/4 of the black line thickness does not seem to work well either as it is not quite rounded enough.

OOPS: I reversed the rounding. Need to use close rather than open.

convert otgd1y.png -morphology close disk:8 result2.gif

Image

It is not clear how you generated the original blocky image. If you used IM, you could draw rounded rectangles. See -draw at http://www.imagemagick.org/Usage/draw/#primitives

Re: achieve this effect

Posted: 2012-05-16T23:52:27-07:00
by Bonzo
There were a couple of posts about this last year but I have no idea what to search for to find them.

Re: achieve this effect

Posted: 2012-05-17T03:24:53-07:00
by mahadazad
I need to replicate exact effect. if you see closely the curve and some of the corners are very different, which are not being generated by morphology with close disk, smooth disk, applying median.

I am 100% sure this effect is achieved by imagemagick as there were some other affects too, which I exactly replicated using imagemagick but this one is a tough one.

I will really appreciate if someone could help me in this matter. I have spent about 2 days but could not achieve this effect.

Thank You

Re: achieve this effect

Posted: 2012-05-17T11:29:18-07:00
by fmw42
I don't know how to do any better than what I explained above. I doubt there is any one unique function in IM that will do that. Perhaps Anthony will have some ideas. My other suggestion is to draw it from scratch using -draw and round rectangles or circles where needed.

Where did you get the idea that IM could do that exactly as desired?

Re: achieve this effect

Posted: 2012-05-17T22:16:15-07:00
by anthony
Note Open and Close will do two aspects of the puzzel. You probably want to do both. 'Smooth' which does a 'Open followed by a Close'

But make sure your disk radius is slightly smaller than 1/2 the line distance or you could wipe out single pixels.

however the diagonal joins make the results a little lop-sided.

As such I think you may be better of either using using dilate or erode using diamond, then reverse the process using disk.

Try this...

Code: Select all

   convert code.png -morphology Dilate Diamond:11 -morphology Erode Disk:11.3 code_1.png
Image

Another alternative is to blur the image using Gaussian, then threshold at 50%, which produces a very weird effect!

Code: Select all

convert code.png -blur 0x5 -threshold 50% code_2.png
Image

So you only then need to figure out what you want done for 'diagonal joins'.

Re: achieve this effect

Posted: 2012-05-17T22:34:40-07:00
by anthony
Note that your image
Image

is actually inconsistent!

Any white squares surrounded by 3 blacks in a corner are in one case left sharp, and in another being rounded.

Also white squares are being treated as differently to black squares!

Finally the results show two different radii of circular archs. A half line thickness, and a full line thickness! That will not be so easily to reproduce!

I think this may be a case of specific 'patterns' of 'pixels' being tiled with a specific shaped tile image. And that is a much more involved process, which may be harder to implement generally. It would be possible, but you need to figure out exactly what 3x3 pattern produces what tile. That is 2^9 or 512 patterns, though that may be quartered with rotations, and halved with mirrors down to 2^6 or 64 unique patterns!

If a diamond neighbour hood is used that reduces to 16 unique patterns. But that does not appear to be the case. For example see the white square surrounded by black on all but one corner!

One pattern missing in the example image is a diagonal line of white squares surrounded by black.


ASIDE: this is actually closely related to other examples I have dealt with. My Kernel2Image script
http://www.imagemagick.org/Usage/scripts/kernel2image
And examples in
http://www.imagemagick.org/Usage/morpho ... rnel2image

Also related to a current 'project' of mine, the expansion of bitmaps of 3-D 'voxels' shapes, into diagrams for building (in the sandbox building game "minecraft")

Re: achieve this effect

Posted: 2012-05-21T06:57:12-07:00
by mahadazad
Thank you guys,
Now I believe its not possible with IM. Anyhow, can you please also tell me how do I smooth the edges of the curves? I am using autotrace but its not producing the correct result. I am using autotrace separately, as I didn't enable it while installing IM.

Re: achieve this effect

Posted: 2012-05-21T09:55:14-07:00
by fmw42

Re: achieve this effect

Posted: 2012-05-21T21:56:01-07:00
by anthony
Using a very small blur to smooth edges is onw way.

Autotrace is better, but may need special options to ensure it correctly determines 'corners'.


The original program that generated the example result, as I think I mentioned probably 'tiled' prepared images for each of the input 'pixel sized' squares. IM can do this but it really needs a highly specialized neighbourhood selection process to generate the array of tiles (which would be pre-drawn and already smoothed). At least for the example result you gave.

Re: achieve this effect

Posted: 2012-05-22T03:25:47-07:00
by mahadazad
Thank You guys,
I used blur with 0.7 value and it worked well.