Page 1 of 1

How to extend an image with stretched edges?

Posted: 2012-11-02T07:31:49-07:00
by laurens_at_hol
I'm working on a tool that can do several operations on an image.
Earlier I was able (with the help of this forum) to create an operation that adds mirrored edges to an image.
In that topic viewtopic.php?f=1&t=22071 I also asked some questions on creating stretched edges on an image.

For the stretched edges I want to have one single convert call that does all the transformations.
I've tried the virtual-pixel 'Edge' option but that is not exactly what I want. I want a range of edge pixels to be stretched, not 1 as is done in the virtual-pixel Edge option.
I've searched for some kind of "resize-part-of-image" option, but I could find it. So I decided that I would crop and resize each edge after each other and then append the different pieces.

I got it working when I do the operations in two convert calls, with the second call using the result image of the first call.
First call crops the part of the image that will be used for the rest of the operations (mpr:big -> center including the edges which will be stretched in the resize operations).
After that the center without the edges is cropped (mpr:center)
Then I crop the left edge (mpr:left) and stretch it (mpr:left_stretched). Then the right edge is cropped (mpr:right) and stretched (mpr:right_stretched).
Then I append the parts together and save it to a file lcr.jpg

Code: Select all

convert original.jpg -crop 2048x1411+0+127 -write mpr:big +delete +repage -crop 1932x1411+58+0 mpr:big -write mpr:center_lr +delete +repage -crop 58x1411+0+0 mpr:big -write mpr:left +delete +repage mpr:left -resize 117x1411! -write mpr:left_stretched +delete +repage -crop 58x1411+1990+0 mpr:big -write mpr:right +delete +repage mpr:right -resize 117x1411! -write mpr:right_stretched +delete +repage -gravity Center +append mpr:left_stretched mpr:center_lr mpr:right_stretched lcr.jpg
Second call is using the created lcr.jpg image for the rest of the operations.
Again the center is cropped (mpr:center_tb -> center without the parts that is used for stretching the top and bottom edges). Then the top is cropped (mpr:top) and stretched (mpr:top_stretched) and also the bottom is cropped (mpr:bottom) and stretched (mpr:bottom_stretched).
Then the final image (stretched.jpg) is created by appending the top, center and bottom.

Code: Select all

convert -crop 2166x1295+0+58 lcr.jpg -write mpr:center_tb +delete +repage -crop 2166x58+0+0 lcr.jpg -write mpr:top +delete +repage mpr:top -resize 2166x117! -write mpr:top_stretched +delete +repage -crop 2166x58+0+1353 lcr.jpg -write mpr:bottom +delete +repage mpr:bottom -resize 2166x117! -write mpr:bottom_stretched +delete +repage -append mpr:top_stretched mpr:center_tb mpr:bottom_stretched +repage stretched.jpg
Problem is that when I want to do this in one call and use -write mpr:lcr instead of saving the first call to lcr.jpg, then the cropping of the top and bottom edges is wrong and the stretched edges are not as excpected (and is the two seperate calls).

Code: Select all

convert original.jpg -crop 2048x1411+0+127 -write mpr:big +delete +repage -crop 1932x1411+58+0 mpr:big -write mpr:center_lr +delete +repage -crop 58x1411+0+0 mpr:big -write mpr:left +delete +repage mpr:left -resize 117x1411! -write mpr:left_stretched +delete +repage -crop 58x1411+1990+0 mpr:big -write mpr:right +delete +repage mpr:right -resize 117x1411! -write mpr:right_stretched +delete +repage -gravity Center +append mpr:left_stretched mpr:center_lr mpr:right_stretched -write mpr:lcr +delete +repage -crop 2166x1295+0+58 mpr:lcr -write mpr:center_tb +delete +repage -crop 2166x58+0+0 mpr:lcr -write mpr:top +delete +repage mpr:top -resize 2166x117! -write mpr:top_stretched +delete +repage -crop 2166x58+0+1353 mpr:lcr -write mpr:bottom +delete +repage mpr:bottom -resize 2166x117! -write mpr:bottom_stretched +delete +repage -append mpr:top_stretched mpr:center_tb mpr:bottom_stretched +repage stretched.jpg
It feels like if all the mpr 'in between images' is messing up the normal flow of operations.

Could anyone help me with this please, so that everything can be done in one call? Thanks!

Re: How to extend an image with stretched edges?

Posted: 2012-11-02T10:11:54-07:00
by fmw42
convert -crop 2166x1295+0+58 lcr.jpg -write mpr:center_tb +delete +repage -crop 2166x58+0+0 lcr.jpg -write mpr:top +delete +repage mpr:top -resize 2166x117! -write mpr:top_stretched +delete +repage -crop 2166x58+0+1353 lcr.jpg -write mpr:bottom +delete +repage mpr:bottom -resize 2166x117! -write mpr:bottom_stretched +delete +repage -append mpr:top_stretched mpr:center_tb mpr:bottom_stretched +repage stretched.jpg
-crop should be done after reading lcr.jpg

Seems like if you fix that, then you should be able to chain the commands into one command line.

Alternately, use clones and parenthesis processing. see http://www.imagemagick.org/Usage/basics/#parenthesis and http://www.imagemagick.org/Usage/basics/#clone

P.S. It is hard to figure out something without the images being used. There is no way to test as you have coded for some particular image (size). If you still have trouble, post a link to your input images and the good and bad output images.