Skip to content

Commit

Permalink
Merge pull request #448 from Alexander-Zangl/master
Browse files Browse the repository at this point in the history
render.py can now export blurred image as .png
  • Loading branch information
rafalkowalewski1 authored Mar 18, 2024
2 parents 87232d1 + 527c4ac commit 6a37c17
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions picasso/gui/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -3532,7 +3532,7 @@ def __init__(self, window):
self.disp_px_size.setSingleStep(10)
self.disp_px_size.setKeyboardTracking(False)
self.disp_px_size.valueChanged.connect(self.update_plots)
mask_grid.addWidget(self.disp_px_size, 0, 1)
mask_grid.addWidget(self.disp_px_size, 0, 1, 1, 2)

mask_grid.addWidget(QtWidgets.QLabel("Blur"), 1, 0)
self.mask_blur = QtWidgets.QDoubleSpinBox()
Expand All @@ -3542,7 +3542,7 @@ def __init__(self, window):
self.mask_blur.setDecimals(5)
self.mask_blur.setKeyboardTracking(False)
self.mask_blur.valueChanged.connect(self.update_plots)
mask_grid.addWidget(self.mask_blur, 1, 1)
mask_grid.addWidget(self.mask_blur, 1, 1, 1, 2)

mask_grid.addWidget(QtWidgets.QLabel("Threshold"), 2, 0)
self.mask_thresh = QtWidgets.QDoubleSpinBox()
Expand All @@ -3552,7 +3552,7 @@ def __init__(self, window):
self.mask_thresh.setDecimals(5)
self.mask_thresh.setKeyboardTracking(False)
self.mask_thresh.valueChanged.connect(self.update_plots)
mask_grid.addWidget(self.mask_thresh, 2, 1)
mask_grid.addWidget(self.mask_thresh, 2, 1, 1, 2)

gridspec_dict = {
'bottom': 0.05,
Expand All @@ -3565,7 +3565,7 @@ def __init__(self, window):
((self.ax1, self.ax2), (self.ax3, self.ax4)),
) = plt.subplots(2, 2, figsize=(6, 6), gridspec_kw=gridspec_dict)
self.canvas = FigureCanvas(self.figure)
mask_grid.addWidget(self.canvas, 3, 0, 1, 2)
mask_grid.addWidget(self.canvas, 3, 0, 1, 3)

self.save_all = QtWidgets.QCheckBox("Mask all channels")
self.save_all.setChecked(False)
Expand All @@ -3582,6 +3582,12 @@ def __init__(self, window):
self.save_mask_button.clicked.connect(self.save_mask)
mask_grid.addWidget(self.save_mask_button, 5, 1)

self.save_blur_button = QtWidgets.QPushButton("Save Blur")
self.save_blur_button.setEnabled(False)
self.save_blur_button.setFocusPolicy(QtCore.Qt.NoFocus)
self.save_blur_button.clicked.connect(self.save_blur)
mask_grid.addWidget(self.save_blur_button, 5, 2)

mask_button = QtWidgets.QPushButton("Mask")
mask_button.setFocusPolicy(QtCore.Qt.NoFocus)
mask_button.clicked.connect(self.mask_locs)
Expand All @@ -3591,7 +3597,7 @@ def __init__(self, window):
self.save_button.setEnabled(False)
self.save_button.setFocusPolicy(QtCore.Qt.NoFocus)
self.save_button.clicked.connect(self.save_locs)
mask_grid.addWidget(self.save_button, 6, 1)
mask_grid.addWidget(self.save_button, 6, 1, 1, 2)

self.cached_oversampling = 0
self.cached_blur = 0
Expand Down Expand Up @@ -3642,6 +3648,7 @@ def blur_image(self):
H_blur = gaussian_filter(self.H, sigma=self.mask_blur.value())
H_blur = H_blur / np.max(H_blur)
self.H_blur = H_blur # image to be displayed in self.ax2
self.save_blur_button.setEnabled(True)

def save_mask(self):
""" Saves binary mask to a .npy and .png format."""
Expand All @@ -3657,6 +3664,17 @@ def save_mask(self):
png_path = base + "_mask" + ".png"
plt.imsave(png_path, self.mask, cmap='gray')

def save_blur(self):
"""Save blurred image to a png. format."""
directory, file_name = os.path.split(self.paths[0])
base, ext = os.path.splitext(file_name)
name_blur = base + "_blur"
path, ext = QtWidgets.QFileDialog.getSaveFileName(
self, "Save blur to", name_blur, filter="*.png"
)
if path:
plt.imsave(path, self.H_blur, cmap=self.cmap)

def load_mask(self):
""" Loads binary mask from .npy format. """

Expand Down

0 comments on commit 6a37c17

Please sign in to comment.