简体   繁体   中英

How to convert visuals image to polar using Vispy

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

使用 Vispy 生成的图像

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在 PolarTransform 之前 Vispy 生成的图像

Image generated by Vispy after PolarTransform PolarTransform 后 Vispy 生成的图像

Code for PolarTransform:

self.img.transform = PolarTransform()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM