|
9 | 9 | import pyqtgraph as pg
|
10 | 10 | from PyQt6 import QtGui
|
11 | 11 |
|
12 |
| -class NonInteractiveHistogramLUTItem(pg.HistogramLUTItem): |
13 |
| - def event(self, event): |
14 |
| - # When in non-interactive mode, simply consume mouse and hover events. |
15 |
| - if event.type() in (QtCore.QEvent.Type.GraphicsSceneMousePress, |
16 |
| - QtCore.QEvent.Type.GraphicsSceneMouseMove, |
17 |
| - QtCore.QEvent.Type.GraphicsSceneMouseRelease, |
18 |
| - QtCore.QEvent.Type.GraphicsSceneHoverEnter, |
19 |
| - QtCore.QEvent.Type.GraphicsSceneHoverMove, |
20 |
| - QtCore.QEvent.Type.GraphicsSceneHoverLeave): |
21 |
| - return True # Consume the event; do nothing. |
22 |
| - return super().event(event) |
23 | 12 |
|
24 | 13 | def update_roi_count(self):
|
25 | 14 | self.roi_count.setText(f'{self.ncells} RoIs')
|
@@ -79,68 +68,63 @@ def update_plot(self):
|
79 | 68 |
|
80 | 69 | vals = self.contrast_slider.value()
|
81 | 70 | image = normalize99(image,lower=vals[0],upper=vals[1])**self.gamma
|
82 |
| - # maybe should not directly modify image? Use viewer isntead? |
| 71 | + # maybe should not directly modify image? Use viewer instead? |
83 | 72 |
|
84 | 73 | if self.invert.isChecked():
|
85 | 74 | image = 1-image
|
86 |
| - |
87 |
| - # restore to uint8 |
88 |
| - image *= 255 |
89 | 75 |
|
90 |
| - # Decide whether to treat it as grayscale or color: |
91 |
| - if image.ndim == 3 and image.shape[-1] == 1: |
92 |
| - # Single-channel (H, W, 1) => reshape to (H, W) so we can apply LUT. |
93 |
| - image = image[..., 0] |
94 |
| - self.img.setImage(image, autoLevels=False) |
95 |
| - elif image.ndim == 3 and image.shape[-1] in (3, 4): |
96 |
| - # Multi-channel (RGB or RGBA): show color image, no LUT. |
97 |
| - self.img.setImage(image, autoLevels=False, lut=None) |
98 |
| - else: |
99 |
| - # Otherwise, assume it's already 2D or something else. |
100 |
| - self.img.setImage(image, autoLevels=False) |
101 |
| - |
102 | 76 | elif self.view==4:
|
103 |
| - image = self.csum#.astype(np.float32)# will need to generalize to Z |
| 77 | + image = self.csum.astype(np.float32)# will need to generalize to Z |
104 | 78 | else:
|
105 | 79 | image = np.zeros((self.Ly,self.Lx), np.uint8)
|
106 | 80 | if len(self.flows)>=self.view-2 and len(self.flows[self.view-1])>0:
|
107 |
| - image = self.flows[self.view-1][self.currentZ] |
| 81 | + image = self.flows[self.view-1][self.currentZ] #/ 255 |
108 | 82 |
|
109 |
| - |
110 |
| - # levels = (0, image.max()) |
111 |
| - # self.img.setImage(image, autoLevels=False)#, levels=levels) |
112 |
| - |
| 83 | + |
113 | 84 | self.hist.set_view(
|
114 | 85 | v=self.view,
|
115 | 86 | preset=self.cmaps[self.view],
|
116 | 87 | default_cmaps=self.default_cmaps
|
117 | 88 | )
|
118 | 89 |
|
119 |
| - # Or manually set the range to 0..8 |
120 |
| - # self.img.setImage(image, autoLevels=False, levels=levels) |
121 |
| - self.img.setImage(image, autoLevels=False) |
122 |
| - |
| 90 | + # Set the histogram levels for the image. |
| 91 | + dmin, dmax = float(image.min()), float(image.max()) |
| 92 | + if dmax == dmin: |
| 93 | + dmax = dmin + 1.0 |
| 94 | + levels = (dmin, dmax) |
| 95 | + lut = None |
| 96 | + |
| 97 | + |
| 98 | + if self.view==4: |
| 99 | + nBands = int(dmax+1) # assuming image values are integers 0..(nBands-1) |
| 100 | + self.hist.setDiscreteMode(True, n_bands=nBands) # this overrides the gradient painting |
| 101 | + # Force image levels to exactly match discrete bands (e.g. 0 to nBands-1) |
| 102 | + levels=(0, nBands-1) |
| 103 | + |
| 104 | + else: |
| 105 | + self.hist.setDiscreteMode(False) # restore continuous mode |
| 106 | + |
| 107 | + print(levels, image.ndim, image.shape, lut) |
| 108 | + |
| 109 | + # Decide whether to treat it as grayscale or color: |
| 110 | + if image.ndim == 3 and image.shape[-1] == 1: |
| 111 | + # Single-channel (H, W, 1) => reshape to (H, W) so we can apply LUT. |
| 112 | + image = image[..., 0] |
| 113 | + self.img.setImage(image, autoLevels=False, levels=levels) |
| 114 | + elif image.ndim == 3 and image.shape[-1] in (3, 4): |
| 115 | + # Multi-channel (RGB or RGBA): show color image, no LUT. |
| 116 | + self.img.setImage(image, autoLevels=False, levels=levels, lut=lut) |
| 117 | + else: |
| 118 | + # Otherwise, assume it's already 2D or something else. |
| 119 | + self.img.setImage(image, autoLevels=False, levels=levels) |
| 120 | + |
| 121 | + |
123 | 122 | self.set_hist_colors()
|
124 | 123 |
|
125 |
| - # self.hist.autoHistogramRange() |
126 |
| - # 3) Now read the user’s chosen region and “zoom” to it |
127 |
| - # mn, mx = self.hist.region.getRegion() |
128 |
| - # self.hist.vb.setRange(xRange=(mn, mx), padding=.05) |
129 |
| - |
130 |
| - # # (Optional) If you want to prevent re‐auto‐ranging each time, |
131 |
| - # # disable autoRange on the histogram’s viewbox: |
132 |
| - # self.hist.vb.enableAutoRange(axis=pg.ViewBox.XAxis, enable=False) |
133 |
| - |
134 |
| - # self.scale.setImage(self.radii, autoLevels=False) |
135 |
| - # self.scale.setLevels([0.0,255.0]) |
136 |
| - #self.img.set_ColorMap(self.bwr) |
137 | 124 | if self.NZ>1 and self.orthobtn.isChecked():
|
138 | 125 | self.update_ortho()
|
139 | 126 |
|
140 |
| - # self.contrast_slider.setLow(self.saturation[self.currentZ][0]) |
141 |
| - # self.contrast_slider.setHigh(self.saturation[self.currentZ][1]) |
142 |
| - # if self.masksOn or self.outlinesOn: |
143 |
| - # self.layer.setImage(self.layerz[self.currentZ], autoLevels=False) #<<< something to do with it |
| 127 | + |
144 | 128 | self.win.show()
|
145 | 129 | self.show()
|
146 | 130 |
|
|
0 commit comments