简体   繁体   English

qwt / pyqt自定义比例尺,用于图像绘图(像素到毫米的转换)

[英]qwt/pyqt custom scale for image plot (pixel to mm conversion)

I've decided to use guiqwt as my main plot library in Python and it works quite well. 我决定将guiqwt用作Python中的主要绘图库,并且效果很好。 However, I'm missing a contour plot feature, so I had to work out my own contours in my image plots. 但是,我缺少轮廓图功能,因此必须在图像图中绘制出自己的轮廓。 That was quite easy by using scikit. 使用scikit相当容易。 Now I have my plot showing the image and the contours on top. 现在,我的绘图在顶部显示图像和轮廓。 Scale unit in x and y-direction is pixel as the image raw data is given per pixel and the calculated contours as well. x和y方向的比例单位是像素,因为每个像素都提供了图像原始数据,并且还计算了轮廓。

My problem is to convert the pixel-scale into eg mm-scale without scaling the image. 我的问题是在不缩放图像的情况下将像素比例转换为毫米比例。 I want to replace the original scale with a scale that represents the measured distances. 我想用代表测量距离的比例尺代替原始比例尺。 The distances are available in an array. 距离在数组中可用。

In my first attempt I tried to change the AxisScaleDivision by creating a new one and using QwtPlot::setAxisScaleDiv. 在我第一次尝试我试图改变AxisScaleDivision通过创建一个新的,使用QwtPlot :: setAxisScaleDiv。 But that seems to work like a zoom-function as the image is reduced to the new interval. 但这似乎像缩放功能一样工作,因为图像被缩小到了新的间隔。

Here is my code for a small example: 这是我的一个小示例代码:

from guiqwt.plot import ImageDialog
from guiqwt.builder import make
from skimage import measure
import numpy as np

data = np.random.rand(80,30)

contours = measure.find_contours(data, 0.1)

win = ImageDialog(edit=False, toolbar=True, wintitle="Contrast test", 
    options=dict(show_contrast=True))

img = make.image(data)

plot = win.get_plot()
plot.add_item(img)

for n, contour in enumerate(contours):
    curve = make.curve(contour[:, 1], contour[:, 0], 'k-')
    plot.add_item(curve)

win.show()

scaleEng = plot.axisScaleEngine(2)
scaleDiv = scaleEng.divideScale(20, 30, 5, 5, 0)

plot.setAxisScaleDiv(2, scaleDiv)
plot.replot()

The syntax is very close to qwt, so I think anybody who is familiar with qwt might be able to help me :) 语法非常接近qwt,所以我认为任何熟悉qwt的人都可以为我提供帮助:)

The image zoom should stay unaltered. 图像缩放应保持不变。 Only the axis should be recalculated to a mm-scale and afterwards, of course, adapted when the zoom function is used. 仅应将轴重新计算为mm刻度,然后,当使用缩放功能时,当然要进行调整。

I solved the problem by using a completely different approach. 我通过使用完全不同的方法解决了这个问题。 I used the xyimage-function of guiqwt. 我使用了guiqwt的xyimage函数。 However, I had to scale my contours too. 但是,我也必须缩放轮廓。 I missed that the last time, that's why I posted the question. 我上次错过了,所以才发布了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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