Question

I have a typical source image with a 3:4 aspect ratio. I also have a set of coordinates that I need to map the image onto in a separate image. The coordinates are not perfectly rectangular; if anything they define an irregular mesh.

So for example, (0,0) might map to (12,33), (120,0) => (127,36), (240,0)=>(226,13), etc.

My goal is to get my source image to fit onto the new shape by mapping the source coordinates to the destination and applying distortion.

What are some ways to accomplish this? I'm using .NET but am fine calling out to e.g. ImageMagick.

EDIT: As requested, here's a picture. The left image is a simple photo, evenly subdivided (ignore my crappy MSPaint skills). The right side shows the target shape. I have coordinates for each dot on the right side. The goal is to map (project?) the flat image onto the shape so that the dots line up.

enter image description here

Was it helpful?

Solution

I have some examples of the distort operators on my site ( http://www.rubblewebs.co.uk/imagemagick/operators/distort.php ) - using php but you will get the idea.

You probably want the shepards method.

$cmd = "$input -matte -virtual-pixel transparent".  
" -distort Shepards \"0,0 0,0  0,100 20,100 0,200".  
" 0,200 133,200 133,180 266,200 266,200 266,100".  
" 246,100 266,0 266,0 133,0 133,20\" ";  
exec("convert $cmd shepards.png");

enter image description here

OTHER TIPS

Look into ImageMagick's Freeform Distorts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top