1

I am trying to convert my visual image to Polar form using Vispy

Something similar to below images..

Original Image generated using below code of Vispy

scene.visuals.Image(self.img_data,interpolation=interpolation,parent = self.viewbox.scene, cmap=self.cmap, method='subdivide', clim=(-65,40)) 

Image generated using Vispy

Required Polar Image: Required Polar Image

I did try to implement polarTransform using PolarTransform Example from Vispy but couldn't succeed.

Can anyone please guide my on how to do polarTransform of above Image to Polar using Vispy.

Thanks

Reply to @djhoese: Image generated by Vispy before PolarTransform Image generated by Vispy before PolarTransform

Image generated by Vispy after PolarTransform Image generated by Vispy after PolarTransform

Code for PolarTransform:

self.img.transform = PolarTransform()
ViNOJ
  • 15
  • 5
  • Could you explain what went wrong when you tried to use the PolarTransform? I've never used it myself, but that seems like the easiest solution...if it works of course. – djhoese Jun 29 '21 at 13:30
  • I tried making a stripped down version of the image_transforms.py example you mentioned and playing with the chain of transforms that are used for the polar image. By adjusting the scale and translate of the second STTransform (the one with `pi` in it) you can get closer to what you're looking for but I couldn't get it all the way. I've also been trying to understand if this is an expected limitation of the PolarTransform by reading docstrings: https://vispy.org/api/vispy.visuals.transforms.nonlinear.html#vispy.visuals.transforms.nonlinear.PolarTransform I'll bring this up to other devs. – djhoese Jul 01 '21 at 14:45
  • I can't elaborate atm, but you will find explanations here in this code snippet https://github.com/wradlib/wradvis/blob/25aafc7281a79796096034bba5f35dfc289861c0/wradvis/glcanvas.py#L214-L256 – kmuehlbauer Jul 01 '21 at 15:58
  • Just a heads up, it might not work by just adding the PolarTransform to the transform chain. In the example I linked above, I'm expecting the one dimension to be 360 to get the correct location from the texture. We might need to add a special PolarImage into vispy to have everything in one place. I'll come back with an answer then. – kmuehlbauer Jul 02 '21 at 14:54
  • @kmuehlbauer Thanks for the update, I am trying to implement it as per the example shared by you. Though there is improvement in the output image, but still more is to be done to achieve the final expected image. – ViNOJ Jul 04 '21 at 17:11
  • @VINOJ I've created a more or less self contained example to discuss with the vispy gitter community. Maybe we can have a chat over there and hopefully come to a solution to present here. Link:https://gitter.im/vispy/vispy?at=60e1e0194e325e6132bc5cf9 – kmuehlbauer Jul 04 '21 at 17:19

1 Answers1

0

ImageVisual and PolarTransform do not play well together without some nudging.

VisPy has two methods of drawing, subdivide and impostor. I'll concentrate on subdivide here. This won't work with impostor.

First, create the ImageVisual like that:

img = visuals.ImageVisual(image, 
                          grid=(1, N),           
                          method='subdivide')

For N use a reasonable high number (eg 360). Playing with that number you'll immediately see how the polar resolution is affected.

Further you need to setup some specific transform chain:

transform = (
             # move to final location and scale to your liking
             STTransform(scale=(scx,scy), translate=(xoff,yoff))

             # 0
             # just plain simple polar transform
             *PolarTransform()

             # 1
             # pre scale image to work with polar transform
             # PolarTransform does not work without this
             # scale vertex coordinates to 2*pi
             * STTransform(scale=(2 * np.pi / img.size[0], 1.0))

             # 2
             # origin switch via translate.y, fix translate.x
             * STTransform(translate=(img.size[0] * (ori0 % 2) * 0.5,                                                                   
                                      -img.size[1] * (ori0 % 2)))

             # 3
             # location change via translate.x
             * STTransform(translate=(img.size[0] * (-loc0 - 0.25), 0.0))

             # 4
             # direction switch via inverting scale.x
             * STTransform(scale=(-dir0, 1.0))

            )
# set transform
img.transform = transform
  • dir0 - Direction cw/ccw (takes values -1/1, respectively)
  • loc0 - Location of Zero (value between 0 and 2 * np.pi, counter clockwise)
  • ori0 - Side which will be transformed to center of polar image (takes values 0, 1 for top or bottom

The bottom four STTransform can surely be simplified. They are split apart to show the different changes and how they have to be applied.

An example will be added to the VisPy examples section later.

kmuehlbauer
  • 441
  • 4
  • 7