Fixed bool / monochrome image display, added more unit tests
This commit is contained in:
parent
748a8433b9
commit
152c5d393f
@ -959,6 +959,8 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
|
||||
elif data.dtype.kind == 'i':
|
||||
s = 2**(data.itemsize*8 - 1)
|
||||
levels = np.array([-s, s-1])
|
||||
elif data.dtype.kind == 'b':
|
||||
levels = np.array([0,1])
|
||||
else:
|
||||
raise Exception('levels argument is required for float input types')
|
||||
if not isinstance(levels, np.ndarray):
|
||||
|
@ -179,8 +179,8 @@ class HistogramLUTItem(GraphicsWidget):
|
||||
return self.lut
|
||||
|
||||
def regionChanged(self):
|
||||
#if self.imageItem is not None:
|
||||
#self.imageItem.setLevels(self.region.getRegion())
|
||||
if self.imageItem() is not None:
|
||||
self.imageItem().setLevels(self.region.getRegion())
|
||||
self.sigLevelChangeFinished.emit(self)
|
||||
#self.update()
|
||||
|
||||
|
@ -379,12 +379,14 @@ class ImageItem(GraphicsObject):
|
||||
eflsize = 2**(image.itemsize*8)
|
||||
ind = np.arange(eflsize)
|
||||
minlev, maxlev = levels
|
||||
levdiff = maxlev - minlev
|
||||
levdiff = 1 if levdiff == 0 else levdiff # don't allow division by 0
|
||||
if lut is None:
|
||||
efflut = fn.rescaleData(ind, scale=255./(maxlev-minlev),
|
||||
efflut = fn.rescaleData(ind, scale=255./levdiff,
|
||||
offset=minlev, dtype=np.ubyte)
|
||||
else:
|
||||
lutdtype = np.min_scalar_type(lut.shape[0]-1)
|
||||
efflut = fn.rescaleData(ind, scale=(lut.shape[0]-1)/(maxlev-minlev),
|
||||
efflut = fn.rescaleData(ind, scale=(lut.shape[0]-1)/levdiff,
|
||||
offset=minlev, dtype=lutdtype, clip=(0, lut.shape[0]-1))
|
||||
efflut = lut[efflut]
|
||||
|
||||
|
@ -60,6 +60,18 @@ def test_ImageItem(transpose=False):
|
||||
img.setLevels([127, 128])
|
||||
assertImageApproved(w, 'imageitem/gradient_mono_byte_levels', 'Mono byte gradient w/ levels to isolate diagonal.')
|
||||
|
||||
# test monochrome image
|
||||
data = np.zeros((10, 10), dtype='uint8')
|
||||
data[:5,:5] = 1
|
||||
data[5:,5:] = 1
|
||||
img.setImage(data)
|
||||
assertImageApproved(w, 'imageitem/monochrome', 'Ubyte image with only 0,1 values.')
|
||||
|
||||
# test bool
|
||||
data = data.astype(bool)
|
||||
img.setImage(data)
|
||||
assertImageApproved(w, 'imageitem/bool', 'Boolean mask.')
|
||||
|
||||
# test RGBA byte
|
||||
data = np.zeros((100, 100, 4), dtype='ubyte')
|
||||
data[..., 0] = np.linspace(0, 255, 100).reshape(100, 1)
|
||||
|
@ -42,7 +42,7 @@ Procedure for unit-testing with images:
|
||||
# pyqtgraph should be tested against. When adding or changing test images,
|
||||
# create and push a new tag and update this variable. To test locally, begin
|
||||
# by creating the tag in your ~/.pyqtgraph/test-data repository.
|
||||
testDataTag = 'test-data-5'
|
||||
testDataTag = 'test-data-6'
|
||||
|
||||
|
||||
import time
|
||||
|
Loading…
Reference in New Issue
Block a user