Mapping an image onto a set of coordinates

穿精又带淫゛_ 提交于 2019-12-01 09:08:45

问题


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.


回答1:


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");




回答2:


Look into ImageMagick's Freeform Distorts.



来源:https://stackoverflow.com/questions/10556956/mapping-an-image-onto-a-set-of-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!