Skip to content

Get ImageView ROI working with both row and col major data#1291

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
ixjlyons:roi-axisorder
Jul 7, 2020
Merged

Get ImageView ROI working with both row and col major data#1291
j9ac9k merged 1 commit intopyqtgraph:masterfrom
ixjlyons:roi-axisorder

Conversation

@ixjlyons
Copy link
Copy Markdown
Member

@ixjlyons ixjlyons commented Jul 5, 2020

Fixes #1280. The comment here is implemented, plus there was a bug in the region averaging for the single-image case. Now the selection is averaged along the y axis of the ROI in both row-major and col-major cases (x axis of the PlotItem should correspond to the x axis of the ROI).

Script I used for testing (along with examples/ImageView.py for testing an image stack):

from skimage import data
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
import numpy as np

# row-major: rows of array are rows of image
# col-major: cols of array are rows of image
rowmajor = False # should still work if this is switched

if rowmajor:
    pg.setConfigOptions(imageAxisOrder='row-major')

app = pg.mkQApp()

win = QtGui.QMainWindow()
win.resize(800, 800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()

# shape: (300, 451, 3), row-major as loaded
img_data = data.chelsea()
if not rowmajor:
    # as if loaded col-major data
    img_data = img_data.swapaxes(0, 1)

imv.setImage(img_data)
imv.roi.setSize((451, 5)) # width, height
imv.ui.roiBtn.click()

app.exec_()

else:
# Average data within entire ROI for each frame
data = data.mean(axis=max(axes)).mean(axis=min(axes))
data = data.mean(axis=axes)
Copy link
Copy Markdown
Member Author

@ixjlyons ixjlyons Jul 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should mention this works for numpy >= 1.7.0 (Feb. 2013), minimum in setup.py is 1.8.0

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 7, 2020

LGTM, thanks for fixing this @ixjlyons !

@j9ac9k j9ac9k merged commit c030180 into pyqtgraph:master Jul 7, 2020
@ixjlyons ixjlyons deleted the roi-axisorder branch September 20, 2020 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pressing ROI on ImageView example causes unhandled exceptions

2 participants