Le dimanche 24 juillet 2016 03:38:57 UTC+2, [email protected] a écrit :
>
> Hello,
> I would like to generate lineprofiles through scaled images
>
> I can generate a
>
> LineROI((20, 20), (40, 0), .1) though it goes from 20 20 to 40 40 in
> user coordinates , ?
>
> I would like to click programmatically the ROI button
>
> Now I can retrieve the XY data array from the ROI plotwidget , with the
> csv exporter
>
>
> thank you,
> yours,
>
> Klaus
>
>
> last pyqtgraph version from macport
>
>
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> from __future__ import division
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> #changer les chemins
> import numpy as np
> import scipy.ndimage as ndi
> import pyqtgraph as pg
> import pyqtgraph.exporters
> from pyqtgraph.Point import Point
> from open_SQUID_image import open_image_file
> from open_SQUID_image import three_points_plain
> from open_SQUID_image import slider
>
> from os import path as pt
>
>
>
>
>
>
>
>
>
>
> ## Create image to display
>
>
>
> class Cross(QDialog):
> def __init__(self,parent = None):
> QWidget.__init__(self)
>
>
>
> self.Form = QWidget()
>
> layout = QVBoxLayout()
> self.Form.setLayout(layout)
>
>
>
> #le plotitem contien ROI button
> self.plt = pg.PlotItem()
> self.plt.setTitle("swapaxes_scaled")
> self.p1 = pg.ImageView(view=self.plt)
>
>
>
> # Disconnect old ROI
> #imv = pg.image(pg.np.random.normal(size=(100, 100)))
>
> self.p1.roi.sigRegionChanged.disconnect(self.p1.roiChanged)
> # Create new ROI and install exactly as done in ImageView.__init__
> self.p1.roi = pg.LineROI((20, 20), (40, 0), .1)
> self.p1.roi.setZValue(20)
> self.p1.view.addItem(self.p1.roi)
> self.p1.roi.hide()
> self.p1.roi.sigRegionChanged.connect(self.p1.roiChanged)
>
>
>
>
>
> #self.p2 = pg.PlotWidget()
>
>
> layout.addWidget(self.p1, 1)
> #layout.addWidget(self.p2, 2)
>
>
> self.data = np.ones((100, 100), dtype=float)
> self.data[45:55, 45:55] = 0
> self.data[25, :] = 5
> self.data[:, 25] = 5
> self.data[75, :] = 5
> self.data[:, 75] = 5
> self.data[50, :] = 10
> self.data[:, 50] = 10
> self.data += np.sin(np.linspace(0, 20, 100)).reshape(1, 100)
> self.data += np.random.normal(size=(100,100))
> self.x_length=100
> self.y_length=100
> self.start_x_mu=1
> self.delta_x_mu=0.8
> self.start_y_mu=1
> self.delta_y_mu=0.5
>
>
> self.x0, self.x1 = (self.start_x_mu,self.start_x_mu+
> self.x_length*self.delta_x_mu)
> self.y0, self.y1 = (self.start_y_mu,
> self.start_y_mu+self.y_length*self.delta_y_mu)
> print "return=X1= {} Y1= {}".format(self.x1,self.y1)
>
> self.xscale, self.yscale = (self.x1-self.x0) / self.data.shape[0],
> (self.y1-self.y0) / self.data.shape[1]
> print "xscale= {} yscale= {}".format(self.xscale,self.yscale)
>
> print "self.data shape before plotting",self.data.shape
> self.p1.setImage(self.data,pos=[self.x0, self.y0],
> scale=[self.xscale, self.yscale])
> self.plt.setAspectLocked(True)
>
>
>
>
>
> self.p1.roi.sigRegionChangeFinished.connect(self.updateFromROI)
>
> self.titi=self.p1.getRoiPlot()
> print type(self.titi)
> self.titi.setVisible(True)
> self.Plot_Item=self.titi.getPlotItem()
>
>
> #proxy = pg.SignalProxy(self.plt.scene().sigMouseMoved,
> rateLimit=60, slot=self.mouseMoved)
>
> self.Form.show()
>
>
>
> def updateFromROI(self):
>
> data,
> coords=self.p1.roi.getArrayRegion(self.data,self.plt,(0,1),returnMappedCoords=True)
>
>
> print "data=", data
> print "coord=",coords
> print self.Plot_Item.listDataItems()
> exporter=pg.exporters.CSVExporter(self.Plot_Item)
>
> exporter.export('tst.csv')
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ## Start Qt event loop unless running in interactive mode or using pyside.
> if __name__=="__main__":
> import math
> import sys
> app=QApplication(sys.argv)
>
> mine_cross=Cross()
>
> app.exec_()
>
>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/bd5ceaac-5968-44fe-9352-720647c62f56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.