-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
675 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import numpy as np | ||
import qimage2ndarray | ||
from PIL import Image, ImageEnhance | ||
from PyQt5 import QtGui | ||
from PyQt5.QtWidgets import (QWidget, QSlider, QHBoxLayout, | ||
QLabel, QApplication) | ||
from PyQt5.QtCore import Qt | ||
import sys | ||
from skimage.io import imread | ||
from operations import QImageToCvMat | ||
|
||
class brightnessContrastSaturation(QWidget): | ||
|
||
def __init__(self, outputImageLabel, stateManager): | ||
super().__init__() | ||
self.outputImageLabel = outputImageLabel | ||
self.stateManager = stateManager | ||
self.initUI() | ||
|
||
def initUI(self): | ||
self.resize(400, 300) | ||
hbox = QHBoxLayout() | ||
|
||
labelBrightness = QLabel('Brightness:', self) | ||
self.sldBrightness = QSlider(Qt.Vertical, self) | ||
self.sldBrightness.setObjectName("brightness") | ||
self.sldBrightness.setFocusPolicy(Qt.NoFocus) | ||
self.sldBrightness.setValue(50) | ||
self.sldBrightness.valueChanged.connect(self.changeValue) | ||
|
||
labelContrast = QLabel('Contrast:', self) | ||
self.sldContrast = QSlider(Qt.Vertical, self) | ||
self.sldContrast.setObjectName("contrast") | ||
self.sldContrast.setFocusPolicy(Qt.NoFocus) | ||
self.sldContrast.setValue(50) | ||
self.sldContrast.valueChanged.connect(self.changeValue) | ||
|
||
labelSaturation = QLabel('Saturation:', self) | ||
self.sldSaturation = QSlider(Qt.Vertical, self) | ||
self.sldSaturation.setObjectName("saturation") | ||
self.sldSaturation.setFocusPolicy(Qt.NoFocus) | ||
self.sldSaturation.setValue(50) | ||
self.sldSaturation.valueChanged.connect(self.changeValue) | ||
|
||
hbox.addWidget(labelBrightness) | ||
hbox.addWidget(self.sldBrightness) | ||
hbox.addSpacing(15) | ||
|
||
hbox.addWidget(labelContrast) | ||
hbox.addWidget(self.sldContrast) | ||
hbox.addSpacing(15) | ||
|
||
hbox.addWidget(labelSaturation) | ||
hbox.addWidget(self.sldSaturation) | ||
hbox.addSpacing(15) | ||
|
||
self.setLayout(hbox) | ||
|
||
self.setWindowTitle('Brightness & Contrast & Saturation') | ||
self.show() | ||
|
||
def changeValue(self, value): | ||
channel =1 | ||
|
||
if self.sender().objectName() == "brightness": | ||
channel = 2 | ||
elif self.sender().objectName() == "contrast": | ||
channel = 0 | ||
|
||
if self.stateManager.outputSource != '': | ||
inputImage = QImageToCvMat(self.stateManager.outputSource) | ||
else: | ||
inputImage = imread(self.stateManager.inputSource) | ||
pilImage = Image.fromarray(np.uint8(inputImage)).convert('RGB') | ||
|
||
if channel == 2: | ||
enhancer = ImageEnhance.Brightness(pilImage) | ||
elif channel == 0: | ||
enhancer = ImageEnhance.Contrast(pilImage) | ||
else: | ||
enhancer = ImageEnhance.Color(pilImage) | ||
|
||
if value > 50: | ||
inputImage = enhancer.enhance(1.1) | ||
if value < 50: | ||
inputImage = enhancer.enhance(0.5) | ||
|
||
outputImage = np.array(inputImage.getdata()).reshape(inputImage.size[0], inputImage.size[1], 3) | ||
outputQImage = qimage2ndarray.array2qimage(outputImage, normalize=True) | ||
self.outputImageLabel.setPixmap(QtGui.QPixmap(outputQImage)) | ||
self.stateManager.imageOperation( | ||
outputQImage) | ||
|
||
|
||
def main(): | ||
app = QApplication(sys.argv) | ||
ex = brightnessContrastSaturation() | ||
sys.exit(app.exec_()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import qimage2ndarray | ||
from PyQt5 import QtGui | ||
from PyQt5.QtWidgets import (QWidget, QSlider, QHBoxLayout, | ||
QLabel, QApplication) | ||
from PyQt5.QtCore import Qt | ||
import sys | ||
from skimage.io import imread | ||
from operations import QImageToCvMat | ||
|
||
|
||
class colorBalance(QWidget): | ||
|
||
def __init__(self, outputImageLabel, stateManager): | ||
super().__init__() | ||
self.outputImageLabel = outputImageLabel | ||
self.stateManager = stateManager | ||
self.initUI() | ||
|
||
def initUI(self): | ||
self.resize(400, 300) | ||
hbox = QHBoxLayout() | ||
|
||
labelRed = QLabel('Red:', self) | ||
self.sldRed = QSlider(Qt.Vertical, self) | ||
self.sldRed.setObjectName("red") | ||
self.sldRed.setFocusPolicy(Qt.NoFocus) | ||
self.sldRed.setValue(50) | ||
self.sldRed.valueChanged.connect(self.changeValue) | ||
|
||
labelGreen = QLabel('Blue:', self) | ||
self.sldGreen = QSlider(Qt.Vertical, self) | ||
self.sldGreen.setObjectName("green") | ||
self.sldGreen.setFocusPolicy(Qt.NoFocus) | ||
self.sldGreen.setValue(50) | ||
self.sldGreen.valueChanged.connect(self.changeValue) | ||
|
||
labelBlue = QLabel('Green:', self) | ||
self.sldBlue = QSlider(Qt.Vertical, self) | ||
self.sldBlue.setObjectName("blue") | ||
self.sldBlue.setFocusPolicy(Qt.NoFocus) | ||
self.sldBlue.setValue(50) | ||
self.sldBlue.valueChanged.connect(self.changeValue) | ||
|
||
hbox.addWidget(labelRed) | ||
hbox.addWidget(self.sldRed) | ||
hbox.addSpacing(15) | ||
|
||
hbox.addWidget(labelGreen) | ||
hbox.addWidget(self.sldGreen) | ||
hbox.addSpacing(15) | ||
|
||
hbox.addWidget(labelBlue) | ||
hbox.addWidget(self.sldBlue) | ||
hbox.addSpacing(15) | ||
|
||
self.setLayout(hbox) | ||
|
||
self.setWindowTitle('Color Balance') | ||
self.show() | ||
|
||
def changeValue(self, value): | ||
channel = 2 | ||
|
||
if self.sender().objectName() == "red": | ||
channel = 0 | ||
elif self.sender().objectName() == "blue": | ||
channel = 1 | ||
|
||
if self.stateManager.outputSource != '': | ||
inputImage = QImageToCvMat(self.stateManager.outputSource) | ||
else: | ||
inputImage = imread(self.stateManager.inputSource) | ||
|
||
outputImage = inputImage | ||
if value > 50: | ||
increaseSize = (255 // 50) * (value - 50) | ||
for i in range(inputImage.shape[0]): | ||
for j in range(inputImage.shape[1]): | ||
pixel = inputImage[i, j][channel] | ||
if pixel + increaseSize >= 255: | ||
outputImage[i, j][channel] = 255 | ||
else: | ||
outputImage[i, j][channel] = pixel + increaseSize | ||
if value < 50: | ||
decreaseSize = (255 // 50) * (50 - value) | ||
for i in range(inputImage.shape[0]): | ||
for j in range(inputImage.shape[1]): | ||
pixel = inputImage[i, j][channel] | ||
if pixel - decreaseSize <= 0: | ||
outputImage[i, j][channel] = 0 | ||
else: | ||
outputImage[i, j][channel] = pixel - decreaseSize | ||
|
||
outputQImage = qimage2ndarray.array2qimage(inputImage, normalize=True) | ||
self.outputImageLabel.setPixmap(QtGui.QPixmap(outputQImage)) | ||
self.stateManager.imageOperation( | ||
outputQImage) | ||
|
||
|
||
def main(): | ||
app = QApplication(sys.argv) | ||
ex = colorBalance() | ||
sys.exit(app.exec_()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from PyQt5 import QtGui, QtCore | ||
from PyQt5.QtWidgets import QRubberBand, QLabel | ||
from PyQt5.QtCore import QRect | ||
|
||
|
||
class cropImage(QLabel): | ||
def __init__(self, outputImageLabel, stateManager, parentQWidget=None): | ||
super(cropImage, self).__init__(parentQWidget) | ||
self.initUI(stateManager) | ||
self.stateManager = stateManager | ||
self.outputImageLabel = outputImageLabel | ||
|
||
def initUI(self, stateManager): | ||
if stateManager.outputSource != '': | ||
inputImage = QtGui.QPixmap(stateManager.outputSource) | ||
else: | ||
inputImage = QtGui.QPixmap(stateManager.inputSource) | ||
self.setWindowTitle("Crop Image") | ||
self.setPixmap(inputImage) | ||
|
||
def mousePressEvent(self, eventQMouseEvent): | ||
self.originQPoint = eventQMouseEvent.pos() | ||
self.currentQRubberBand = QRubberBand(QRubberBand.Rectangle, self) | ||
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, QtCore.QSize())) | ||
self.currentQRubberBand.show() | ||
|
||
def mouseMoveEvent(self, eventQMouseEvent): | ||
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, eventQMouseEvent.pos()).normalized()) | ||
|
||
def mouseReleaseEvent(self, eventQMouseEvent): | ||
self.currentQRubberBand.hide() | ||
currentQRect = self.currentQRubberBand.geometry() | ||
self.currentQRubberBand.deleteLater() | ||
cropQPixmap = self.pixmap().copy(currentQRect) | ||
self.outputImageLabel.setPixmap(QtGui.QPixmap(cropQPixmap)) | ||
self.stateManager.imageOperation( | ||
cropQPixmap.toImage()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ui import Ui_MainWindow | ||
from PyQt5 import QtWidgets | ||
import sys | ||
import os | ||
|
||
os.environ['DISPLAY'] = ':0' | ||
|
||
|
||
class mainWindow(QtWidgets.QMainWindow): | ||
def __init__(self): | ||
super(mainWindow, self).__init__() | ||
self.ui = Ui_MainWindow() | ||
self.ui.setupUi(self) | ||
|
||
|
||
|
||
app = QtWidgets.QApplication([]) | ||
|
||
MainWindow = mainWindow() | ||
MainWindow.setWindowTitle("Ismail & Mustafa Image Editor") | ||
MainWindow.show() | ||
|
||
|
||
sys.exit(app.exec_()) |
Oops, something went wrong.