Non-Linear thumbnail resize?
Non-Linear thumbnail resize?
I'm currently batch-resizing my 2:3 pictures to 1:1 thumbnails, thus cutting off a bit off the sides. What I'd like to do is do a non-linear squeeze by compressing the sides a bit, thus giving a bit more of an impression of the whole image w/o distorting the center.
I see IM has the -distort parameter (http://www.imagemagick.org/script/comma ... hp#distort) but the amount of options is completely beyond my comprehension. Could anyone give me a hint on how to achieve this non-linear compression? I remember AviSynth having something like this so you can watch a bit more of 16:9 videos on a 4:3 screen.
Thanks for any help!
I see IM has the -distort parameter (http://www.imagemagick.org/script/comma ... hp#distort) but the amount of options is completely beyond my comprehension. Could anyone give me a hint on how to achieve this non-linear compression? I remember AviSynth having something like this so you can watch a bit more of 16:9 videos on a 4:3 screen.
Thanks for any help!
Re: Non-Linear thumbnail resize?
What you want is -liquid-rescale although last time I looked the options were very limited. It would be nice to define with a mask ( like Gimp ) which areas can or canot be modified.
Re: Non-Linear thumbnail resize?
Hmmyes, that's about it, but as you've said it's not very configurable. At least some parameter for the curve would be required for me, i.e. being able to specify how much stronger the edges are to compressed vs. the center.Bonzo wrote:What you want is -liquid-rescale although last time I looked the options were very limited. It would be nice to define with a mask ( like Gimp ) which areas can or canot be modified.
Is some dev reading this or should I re-post a feature request to the developers subforum?
Re: Non-Linear thumbnail resize?
More options were discussed when -liquid-rescale was first introduced and I am not sure anything happened. I doubt anything much will happen now for a while as the developers are working hard on version 7.
Anthony has some notes on it here http://www.imagemagick.org/Usage/resize/#liquid-rescale with some other resize methods
Anthony has some notes on it here http://www.imagemagick.org/Usage/resize/#liquid-rescale with some other resize methods
Re: Non-Linear thumbnail resize?
Ok, I do hope v7 is progressing, seemed to be a bit suck when I last looked with all changes happening in v6.Bonzo wrote:More options were discussed when -liquid-rescale was first introduced and I am not sure anything happened. I doubt anything much will happen now for a while as the developers are working hard on version 7
In the meantime, I managed to make -liquid-rescale working for me but cropping the thumbnails nearly to 1:1 and then doing the rest in a non-linear way ... thus, the distortion isn't as visible and I get a tiny bit more preview of the 2:3 original.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Non-Linear thumbnail resize?
Suppose the input is 600x400 pixels, so the output is 400x400.
Suppose you want the centre 50% of the 1:1 image undistorted, so that is 200 pixels wide, or 33.3% of the input. The left-hand 100 pixels of the output will be 200 pixels (33.3%) of the input width. Likewise the right-hand side. We can do this in three chunks, with a simple resize of the two sides. Windows BAT script:
squishIn.png:
squishOut.png
A more flexible method would use displacement maps. This could give a smooth change of scale, so the diagonal lines wouldn't be "broken", but would be curved at the sides.
Suppose you want the centre 50% of the 1:1 image undistorted, so that is 200 pixels wide, or 33.3% of the input. The left-hand 100 pixels of the output will be 200 pixels (33.3%) of the input width. Likewise the right-hand side. We can do this in three chunks, with a simple resize of the two sides. Windows BAT script:
Code: Select all
call %PICTBAT%grid 600 400 8 4 1 Black None
%IM%convert ^
-size 600x400 ^
-background yellow -fill Blue ^
-gravity Center ^
caption:Hello ^
grid.png -composite ^
squishIn.png
%IM%convert ^
squishIn.png ^
( -clone 0 -gravity West ^
-crop 200x0+0+0 +repage ^
-resize 50%%x100%% ) ^
( -clone 0 -gravity Center ^
-crop 200x0+0+0 +repage ) ^
( -clone 0 -gravity East ^
-crop 200x0+0+0 +repage ^
-resize 50%%x100%% ) ^
-delete 0 ^
+append ^
squishOut.png
squishOut.png
A more flexible method would use displacement maps. This could give a smooth change of scale, so the diagonal lines wouldn't be "broken", but would be curved at the sides.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Non-Linear thumbnail resize?
I did some test with liquid-rescale a while back, which you can find at http://www.fmwconcepts.com/misc_tests/l ... index.html.
Alternately, you create a displacement map that protects the center area and compresses the left and right sides some. See http://www.imagemagick.org/Usage/mappin ... ement_maps
Alternately, you create a displacement map that protects the center area and compresses the left and right sides some. See http://www.imagemagick.org/Usage/mappin ... ement_maps
Re: Non-Linear thumbnail resize?
So using a displacement map the command would look something like this?
Code: Select all
convert image.jpg displace_map.jpg -liquid-rescale 75x100%! output.jpg
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Non-Linear thumbnail resize?
I don't use or know much about "-liquid-rescale". Here's an example of a displacement map:
squishMap.png:
squishOut2.png:
Code: Select all
%IM%convert ^
-size 1x100 xc:black ^
-size 1x400 gradient:black-white ^
-size 1x100 xc:white ^
-append ^
+sigmoidal-contrast 5x50%% ^
( -size 1x600 gradient:black-white ) ^
-rotate -90 ^
-compose Mathematics ^
-define compose:args=0,-0.5,0.5,0.5 ^
-composite ^
-scale "600x400^!" ^
squishMap.png
%IM%convert ^
squishIn.png ^
squishMap.png ^
-compose Displace -set option:compose:args 600x0 -composite ^
-gravity Center -crop 400x400+0+0 +repage ^
squishOut2.png
squishOut2.png:
snibgo's IM pages: im.snibgo.com
Re: Non-Linear thumbnail resize?
The displacement idea looks great, but if I apply the above sample in a real world photo it shows strange artifacts (using latest im6)?
EDIT: solved.
EDIT: solved.
Last edited by Marsu42 on 2015-04-12T10:35:38-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Non-Linear thumbnail resize?
My result from your horse is fine. I'm using "Version: ImageMagick 6.9.0-10 Q16 x64". What is your version?
My map is 16 bits/channel/pixel. Yours is only 8, so you have quantization (rounding) errors.
My map is 16 bits/channel/pixel. Yours is only 8, so you have quantization (rounding) errors.
snibgo's IM pages: im.snibgo.com
Re: Non-Linear thumbnail resize?
Thanks, that's it - I was indeed using the Q8 version. I know it doesn't make much of a difference, but I don't want to use Q16 for everything because when processing thousands of images on a slow box everything helps.snibgo wrote:My map is 16 bits/channel/pixel. Yours is only 8, so you have quantization (rounding) errors.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Non-Linear thumbnail resize?
You only need to make the mask once, for all photos of that size. But the displacement also needs Q16.
When pixels are slightly the wrong colour, it doesn't matter much. But pixels in slightly the wrong position is far more noticeable.
When pixels are slightly the wrong colour, it doesn't matter much. But pixels in slightly the wrong position is far more noticeable.
snibgo's IM pages: im.snibgo.com
Re: Non-Linear thumbnail resize?
Yeah, I'm already caching all masks I can when doing bulk operations - but a complicated convert still takes a lot of time. But it's worth it, IM gives me great results (though I am not up to complicated command lines yet) and this displacement method definitely beats every thumbnail generation I've seen yet!snibgo wrote:You only need to make the mask once, for all photos of that size. But the displacement also needs Q16.