Edit book: Add a new image filter: Normalize -- to improve the contrast in images

This commit is contained in:
Kovid Goyal 2016-05-06 20:23:57 +05:30
parent dd9e27fdf7
commit c99232091f
2 changed files with 14 additions and 1 deletions

View File

@ -21,7 +21,7 @@ from calibre.gui2.dnd import (
IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog)
from calibre.gui2.tweak_book import capitalize
from calibre.utils.imghdr import identify
from calibre.utils.img import remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle
from calibre.utils.img import remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle, normalize
def painter(func):
@wraps(func)
@ -149,6 +149,13 @@ class Despeckle(Command):
def __call__(self, canvas):
return despeckle(canvas.current_image)
class Normalize(Command):
TEXT = _('Normalize image')
def __call__(self, canvas):
return normalize(canvas.current_image)
class Replace(Command):
''' Replace the current image with another image. If there is a selection,
@ -368,6 +375,11 @@ class Canvas(QWidget):
self.undo_stack.push(Despeckle(self))
return True
@imageop
def normalize_image(self):
self.undo_stack.push(Normalize(self))
return True
# The selection rectangle {{{
@property
def dc_size(self):

View File

@ -273,6 +273,7 @@ class Editor(QMainWindow):
m.addAction(_('Sharpen image'), self.sharpen_image)
m.addAction(_('Blur image'), self.blur_image)
m.addAction(_('De-speckle image'), self.canvas.despeckle_image)
m.addAction(_('Improve contrast (normalize image)'), self.canvas.normalize_image)
self.info_bar = b = self.addToolBar(_('Image information bar'))
b.setObjectName('image_info_bar')