add mirrored edges to picture

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
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

add mirrored edges to picture

Post by laurens_at_hol »

Hi I'm working on a tool that can add mirrored edges to a picture.
I would like to do the complete transformation in one single convert call.

What I now have is this:

Code: Select all

convert -flip test.jpg -write mpr:flipped +delete -crop 2048x136+0+0 mpr:flipped -write mpr:bottom +delete -crop 2048x136+0+1400 mpr:flipped -write mpr:top +delete -append mpr:top test.jpg mpr:bottom -write mpr:tcb +delete -flop mpr:tcb -write mpr:flopped +delete mpr:flopped -crop 136x1808+0+0 result.jpg
This is throwing the following error: "

Code: Select all

convert: geometry does not contain image `flopped' @ warning/transform.c/CropImage/572.
"

When I run this command that does the first part of the mirroring (top and bottom), it does work and I get the flopped image with mirrored top and bottom edges.

Code: Select all

convert -flip test.jpg -write mpr:flipped +delete -crop 2048x136+0+0 mpr:flipped -write mpr:bottom +delete -crop 2048x136+0+1400 mpr:flipped -write mpr:top +delete -append mpr:top test.jpg mpr:bottom -write mpr:tcb +delete -flop mpr:tcb flopped.jpg
Can anyone help me with this? Can't the flopped image be read from memory?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: add mirrored edges to picture

Post by fmw42 »

The best way to extend the image so that it has mirrored edges is to use the viewport with distort SRT. see http://www.imagemagick.org/Usage/distor ... t_viewport

just set the -filter point and provide the viewport appropriately and -virtual-pixel mirror.

I use that in my script, imageborder, at the link below with various kinds of extended borders.
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

Re: add mirrored edges to picture

Post by laurens_at_hol »

Thanks for your reply Fred. That was just what I was looking for.

If it's not too much trouble, maybe you can help me with another related question.
About the virtual-pixel Edge option: http://www.imagemagick.org/Usage/misc/#edge

I tried the Edge option on some photo's but the result is very unnatural looking edges that look like colored barcodes.
Do you know if it is possible to not use 1 pixel for filling the virtual edge pixels, but a range of multiple edge pixels? So that the edges will have a bit more natural look?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: add mirrored edges to picture

Post by fmw42 »

All that virtual pixel edge does is use the outer rows and columns and extends them horizontally and vertically accordingly. That is why it looks striped. Perhaps some other option may be better.

You can see all the options at

convert -list virtual-pixel

you could try

dither
random
tile

Otherwise, you would need to process the image to add the edge border, then blur or dither the whole thing, then overlay the original, unextended image into the center of the extra processed image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: add mirrored edges to picture

Post by anthony »

You could try blurring the picture, expand the edges, then overlaying the original.

Or expand the image, and variable blur the edges of the image.
See Variable Blurring...
http://www.imagemagick.org/Usage/mapping/#blur
The blur map (amount of blur in each pixel) can be controlled using the morphology distance function, but a mask to just blur the expanded (edge) pixels should also work...

The former is probably good enough...

Hmm.... This is already present in, Thumbnails, Self Framing, Third Example.
http://www.imagemagick.org/Usage/thumbnails/#self_frame
The example also brightens the extended pixels by 20%, and adds a dividing border as well.
Image

It also mentioned to try a blurred 'Dithered Virtual Pixels' instead, that should have less barcode effect within 32 pixels of the original image. I just added this example, producing a cloth-like border effect. (give it an hour or so to appear)
Image

There are lots of ways to skin a cat, and what method you use depends on what you want that skin for, and how messy you like the results!

Let us know what you come up with.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

Re: add mirrored edges to picture

Post by laurens_at_hol »

Thanks for your answers. I got the mirrored edges to work like I wanted with this:

Code: Select all

convert test.jpg -crop 2048x1365+0+0 -set option:distort:viewport 2322x1639-137-137 -virtual-pixel Mirror -filter point -distort SRT 0 +repage mirrored.jpg
For the stretched edges I don't want to blur edges or tiled or any of the other options.
I would like to stretch a certain amount of edge pixels. So like the virtual-pixel 'Edge' option but then for a range of edge pixels instead of 1.
Something like a resize action for the edge parts of the image.

So far I got this:

Code: Select all

convert test.jpg -resize 2172x1660 -write mpr:big +delete -crop 2048x62+62+0 mpr:big -write mpr:top +delete mpr:top -resize 2048x124\! -write mpr:top_stretched +delete -crop 62x1536+2110+62 mpr:big -write mpr:right +delete mpr:right -resize 124x1536\! -write mpr:right_stretched +delete -crop 2048x62+62+1598 mpr:big -write mpr:bottom +delete mpr:bottom -resize 2048x124\! -write mpr:bottom_stretched +delete -crop 62x1536+0+62 mpr:big -write mpr:left +delete mpr:left -resize 124x1536\! -write mpr:left_stretched +delete -crop 2048x1536+62+62 mpr:big -write mpr:center +delete +append mpr:left_stretched mpr:center mpr:right_stretched -write mpr:lcr +delete -gravity Center -append mpr:top_stretched mpr:lcr mpr:bottom_stretched stretched.jpg
I take 68 pixels on each edge and resize that to 124 pixels. The final "stretched.jpg" image has 'empty' corners, but I would like to have these areas also filled.

Is there another (shorter and faster) way to get this kind of stretched edges?
Post Reply