Skip to content

Commit 90cb29c

Browse files
affinity sum view discrete
1 parent 8169885 commit 90cb29c

File tree

17 files changed

+254
-243
lines changed

17 files changed

+254
-243
lines changed

docs/.DS_Store

0 Bytes
Binary file not shown.

docs/examples/.DS_Store

0 Bytes
Binary file not shown.

docs/examples/mono_channel_bact.ipynb

Lines changed: 26 additions & 87 deletions
Large diffs are not rendered by default.

docs/test_files/.DS_Store

0 Bytes
Binary file not shown.

docs/test_files/self_contact.tif

-166 KB
Binary file not shown.

scripts/.DS_Store

0 Bytes
Binary file not shown.

src/.DS_Store

0 Bytes
Binary file not shown.

src/cellpose_omni/gui/MainWindowModules/image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def recenter(self):
112112
self.quadbtns.button(b).setChecked(False)
113113
self.quadbtns.setExclusive(True)
114114

115-
print('recentering')
116115

117116
def eventFilter(self, obj, event):
118117
# Filter events only for the viewport, ignoring sliders/other widgets.

src/cellpose_omni/gui/MainWindowModules/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def compute_model(self):
456456
else:
457457
self.flows[2] = np.zeros_like(self.flows[1])
458458

459-
print('computing model', masks.shape)
460459
self.masks = masks
460+
461461
# boundary and affinity
462462
bounds = flows[-1]
463463
augmented_affinity = flows[-2]
@@ -480,7 +480,6 @@ def compute_model(self):
480480
else:
481481
self.bounds = bounds
482482

483-
print('updating affinity', self.csum.max(), self.affinity_graph.shape)
484483
self.pixelGridOverlay.initialize_colors_from_affinity()
485484
# self.pixelGridOverlay.reset()
486485

src/cellpose_omni/gui/MainWindowModules/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_channels(self):
2626

2727

2828
def compute_scale(self):
29-
print('deprecate this?')
29+
# print('deprecate this?')
3030
self.diameter = float(self.Diameter.text())
3131
self.pr = int(float(self.Diameter.text()))
3232
# self.radii_padding = int(self.pr*1.25)

src/cellpose_omni/gui/MainWindowModules/update.py

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
import pyqtgraph as pg
1010
from PyQt6 import QtGui
1111

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)
2312

2413
def update_roi_count(self):
2514
self.roi_count.setText(f'{self.ncells} RoIs')
@@ -79,68 +68,63 @@ def update_plot(self):
7968

8069
vals = self.contrast_slider.value()
8170
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?
8372

8473
if self.invert.isChecked():
8574
image = 1-image
86-
87-
# restore to uint8
88-
image *= 255
8975

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-
10276
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
10478
else:
10579
image = np.zeros((self.Ly,self.Lx), np.uint8)
10680
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
10882

109-
110-
# levels = (0, image.max())
111-
# self.img.setImage(image, autoLevels=False)#, levels=levels)
112-
83+
11384
self.hist.set_view(
11485
v=self.view,
11586
preset=self.cmaps[self.view],
11687
default_cmaps=self.default_cmaps
11788
)
11889

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+
123122
self.set_hist_colors()
124123

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)
137124
if self.NZ>1 and self.orthobtn.isChecked():
138125
self.update_ortho()
139126

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+
144128
self.win.show()
145129
self.show()
146130

src/cellpose_omni/gui/gui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from PyQt6.QtGui import QSurfaceFormat
2222
fmt = QSurfaceFormat()
2323
fmt.setStencilBufferSize(8) # 8-bit stencil
24+
fmt.setSamples(0) # Disable multisampling to avoid stipple artifacts - doesn't help
2425
QSurfaceFormat.setDefaultFormat(fmt)
2526

2627
os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'

0 commit comments

Comments
 (0)