Search code examples
wand

Implode on specified position on image


I have a question regarding the implode function (https://docs.wand-py.org/en/0.6.7/guide/fx.html#implode). Is there any possibility to use the implode function for a point in the image that is not the center? By passing e.g. a tuple of coordinates?


Solution

  • I'll share my workaround just in case. I've written a small script to find out the position of the point I want to implode by clicking on it on the image with the mouse. I end up with coordinates (e.g. 40,30 in a image with the shape 100, 100).

    In the next step I'd have to somehow "move" my pixel at 40,30 into the image center. To do so I've decided to add borders around my image accordingly (with cv2). So I'll have to add 20 horizontally on the left side of my image (so the image is 120,100 and my pixel at 40,30 has the same distance to each border (60 to the right, 60 to the left). I do the same for the vertical axis and end up, in this case, with an image with the dimension of 120x140.

    Now I cam implode at my specified point and everything is able to being automated if I cover four cases of the point I want to implode at is either higher or lower of h/2 or w/2 so I know on which side I have to add the border.

    Afterwards you can use the trim function to get rid of the extended border and you're good to go.