-interpolate NearestNeighbor behavior

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
the7trumpets
Posts: 3
Joined: 2014-03-12T16:12:07-07:00
Authentication code: 6789

-interpolate NearestNeighbor behavior

Post by the7trumpets »

I am attempting to do 2d 2nd order polynomial warping of an image with a collection of control points.

I need the borders between two color regions to not be interpolated at all. If the source image goes from #00FF00 to #FF0000, then I want the warped image to also have that same transition (though at a different pixel location. I'm also using virtual-pixel Black to ensure that the edges of the warped image stay black.

Code: Select all

convert IN_FILE -virtual-pixel Black -interpolate NearestNeighbor -distort polynomial "2 $(cat control_points.txt)" OUT_FILE
However, the output of this shows interpolated boundaries with various colors between the two present in the source image at the border. I have also tried -interpolate Integer, and -filter Point, with the exact same effects I am seeing from the above command, where interpolated values are being added to the borders.


How do I apply a distortion without any interpolation, and retain 'hard' edges of the same color boundary in the source image?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -interpolate NearestNeighbor behavior

Post by snibgo »

I think "-distort" uses "-filter", not "-interpolate". See http://www.imagemagick.org/script/comma ... hp#distort

Try "-filter box" or "-filter point".
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -interpolate NearestNeighbor behavior

Post by anthony »

As you guessed.. add "-filter point" then distort will use fast 'point interpolation' for color determination.
EG:
-filter point -interpolate nearest

Many examples of doing this is in IM examples distortion
http://www.imagemagick.org/Usage/distor ... nterpolate
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
the7trumpets
Posts: 3
Joined: 2014-03-12T16:12:07-07:00
Authentication code: 6789

Re: -interpolate NearestNeighbor behavior

Post by the7trumpets »

Thanks for the help. I have tried:

-filter Point
Same results as -interpolate NearestNeighbor

-filter Box
ALMOST what I'm looking for. There is only a single interpolated value instead of a smooth gradient along the borders.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -interpolate NearestNeighbor behavior

Post by fmw42 »

try -filter point -interpolate nearestneighbor

I believe that -filter point turns off EWA resampling and then allows -interpolate to work.
the7trumpets
Posts: 3
Joined: 2014-03-12T16:12:07-07:00
Authentication code: 6789

Re: -interpolate NearestNeighbor behavior

Post by the7trumpets »

fmw42 wrote:try -filter point -interpolate nearestneighbor

I believe that -filter point turns off EWA resampling and then allows -interpolate to work.
That did it. Thanks a million!

FYI, that was not intuitive based on the documentation :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -interpolate NearestNeighbor behavior

Post by fmw42 »

Post Reply