Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to specify whether to apply a smooth to the picture. #1463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ def __init__(
checked=self._config["keep_prev_scale"],
enabled=True,
)
smoothPixmap = action(
self.tr("&Smooth Pixmap"),
self.enableSmoothPixmap,
tip=self.tr("Whether smooth pixmap"),
checkable=True,
checked=self._config["canvas"]["smooth_pixmap"],
enabled=True,
)
fitWindow = action(
self.tr("&Fit Window"),
self.setFitWindow,
Expand Down Expand Up @@ -652,6 +660,7 @@ def __init__(
zoomOut=zoomOut,
zoomOrg=zoomOrg,
keepPrevScale=keepPrevScale,
smoothPixmap=smoothPixmap,
fitWindow=fitWindow,
fitWidth=fitWidth,
brightnessContrast=brightnessContrast,
Expand Down Expand Up @@ -760,6 +769,7 @@ def __init__(
zoomOut,
zoomOrg,
keepPrevScale,
smoothPixmap,
None,
fitWindow,
fitWidth,
Expand Down Expand Up @@ -1549,6 +1559,11 @@ def enableKeepPrevScale(self, enabled):
self._config["keep_prev_scale"] = enabled
self.actions.keepPrevScale.setChecked(enabled)

def enableSmoothPixmap(self, enabled):
self._config["canvas"]["smooth_pixmap"] = enabled
self.actions.smoothPixmap.setChecked(enabled)
self.paintCanvas()

def onNewBrightnessContrast(self, qimage):
self.canvas.loadPixmap(QtGui.QPixmap.fromImage(qimage), clear_shapes=False)

Expand Down Expand Up @@ -1718,6 +1733,7 @@ def resizeEvent(self, event):

def paintCanvas(self):
assert not self.image.isNull(), "cannot paint null image"
self.canvas.smooth_pixmap = self._config["canvas"]["smooth_pixmap"]
self.canvas.scale = 0.01 * self.zoomWidget.value()
self.canvas.adjustSize()
self.canvas.update()
Expand Down
1 change: 1 addition & 0 deletions labelme/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ canvas:
linestrip: false
ai_polygon: false
ai_mask: false
smooth_pixmap: true

shortcuts:
close: Ctrl+W
Expand Down
8 changes: 5 additions & 3 deletions labelme/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, *args, **kwargs):
self.setFocusPolicy(QtCore.Qt.WheelFocus)

self._ai_model = None
self.smooth_pixmap = True

def fillDrawing(self):
return self._fill_drawing
Expand Down Expand Up @@ -686,9 +687,10 @@ def paintEvent(self, event):

p = self._painter
p.begin(self)
p.setRenderHint(QtGui.QPainter.Antialiasing)
p.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
p.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
if self.smooth_pixmap:
p.setRenderHint(QtGui.QPainter.Antialiasing)
p.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
p.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)

p.scale(self.scale, self.scale)
p.translate(self.offsetToCenter())
Expand Down