Using Distortion Lookup Maps

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
ian
Posts: 2
Joined: 2013-09-04T09:57:24-07:00
Authentication code: 6789

Using Distortion Lookup Maps

Post by ian »

Hi,

I'm trying to use a a distortion lookup map (LUT) to apply complex transformation to an image. The idea is to apply the transformations to LUT in photoshop so I can process hundreds of images the same way.
But I'm having problems with higher-than-poststamp resolutions, here's my LUT (no transformation, 16bit PNG) :

Image

Here's my input image:

Image

Command (from manual) and output:

Code: Select all

 convert input.png -matte lut.png \
          \( -clone 0,1  -fx 'p{v.r*w,v.g*h}' \
             +clone -compose Dst_In -composite \) -delete 0,1 \
          result.png
Image

As you can see even though I used 16bit channels which should be enough for this resolution the edges on the result are jagged. It seems like interpolation problem.
Is this is my LUT's fault (created in Photoshop, I don't know how to check how precise the gradient is) or is it caused by ImageMagick?

Do you have any large 1-1 LUT I could you? Or even better, could you help me generate one with image magick?

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

Re: Using Distortion Lookup Maps

Post by fmw42 »

Code: Select all

convert input.png -matte lut.png \
          \( -clone 0,1  -fx 'p{v.r*w,v.g*h}' \
             +clone -compose Dst_In -composite \) -delete 0,1 \
          result.png

What version of IM are you using and what platform. It looks perfectly smooth on my IM 6.8.6.9 Q16 Mac.

However, I am puzzled why the result is smaller than the input if this is supposed to be a non-warped result equal to the input.


Your code is also doing more than I would expect. If you do

convert input.png lut.png -fx 'p{v.r*w,v.g*h}' result3.png

Then the result is exactly the same with less code.


Furthermore, I think the proper expression should be

convert input.png lut.png -fx 'p{v.r*(w-1),v.g*(h-1)}' result3.png

since w and h are not the last pixels in the image and thus outside the image.


see the example "The NO-OP Distortion Map revisited" at http://www.imagemagick.org/Usage/mappin ... rtion_maps


The following is a perfect match.

convert input.png \
\( -size 400x1024 gradient: -rotate 90 \) \
\( -size 1024x400 gradient: -rotate 180 \) \
-fx 'p{u[1]*(w-1),u[2]*(h-1)}' result4.png


This would be your equivalent with gradients built on the fly and saved to a newlut.png image.

convert input.png \
\( -size 400x1024 gradient: -rotate 90 \) \
\( -size 1024x400 gradient: -rotate 180 \) \
\( -size 1024x400 xc:black \) \
\( -clone 1 -clone 2 -clone 3 -combine -colorspace sRGB -write newlut.png \) \
-delete 1,2,3 -fx 'p{v.r*(w-1),v.g*(h-1)}' result5.png

The above give a perfect match.



So it is clear that your color gradient lut image is malformed.


If I use my newlut.png, then

convert input.png newlut.png -fx 'p{v.r*(w-1),v.g*(h-1)}' result6.png

works fine.

Image

Note the result above is cut off on the right because it is too wide for display in this forum. But if you download it, you should get the whole thing.
ian
Posts: 2
Joined: 2013-09-04T09:57:24-07:00
Authentication code: 6789

Re: Using Distortion Lookup Maps

Post by ian »

Hi fmw42,

thank you very much for help! Sorry for not including my IM version, it's 6.6.9-7 but it's not relevant since you have right: my LUT was wrong. I generated one using gradients and it all works perfectly now.

Thank you again,
ian
Post Reply