-
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
536 additions
and
9 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,24 @@ | ||
from PyQt5.QtGui import QImage | ||
from PIL import Image | ||
from PyQt5.QtGui import QPixmap | ||
from matplotlib import pyplot as plt | ||
from python.operation import * | ||
import numpy as np | ||
from skimage.filters import roberts, sobel, scharr, prewitt | ||
|
||
|
||
class BoundariesOperation(Operation): | ||
@staticmethod | ||
def execute(input_pixmap, filter_number): | ||
grayscale = qpixmap_to_pil_image(input_pixmap).convert('L') | ||
if filter_number == 1: | ||
edges = roberts(grayscale) | ||
elif filter_number == 2: | ||
edges = prewitt(grayscale) | ||
elif filter_number == 3: | ||
edges = scharr(grayscale) | ||
elif filter_number == 4: | ||
edges = sobel(grayscale) | ||
array = np.uint8(plt.cm.gist_earth(edges) * 255) | ||
output_qimage = image_to_qimage(Image.fromarray(array)).convertToFormat(QImage.Format_Grayscale8) | ||
return QPixmap.fromImage(output_qimage) |
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,3 @@ | ||
#!/bin/bash | ||
pyuic5 mainwindow.ui -o mainwindow.py | ||
|
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
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
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,31 @@ | ||
from PIL.ImageQt import ImageQt | ||
from PyQt5.QtCore import QBuffer | ||
from PyQt5.QtCore import QIODevice | ||
from PyQt5.QtGui import QImage | ||
from PIL import Image | ||
import io | ||
|
||
|
||
class Operation(object): | ||
@staticmethod | ||
def execute(input_pixmap): | ||
return input_pixmap | ||
|
||
|
||
def qpixmap_to_pil_image(pixmap): | ||
image = QImage(pixmap) | ||
buffer = QBuffer() | ||
buffer.open(QIODevice.ReadWrite) | ||
image.save(buffer, "PNG") | ||
|
||
strio = io.BytesIO() | ||
strio.write(buffer.data()) | ||
buffer.close() | ||
strio.seek(0) | ||
byte_img = strio.read() | ||
data_bytes = io.BytesIO(byte_img) | ||
return Image.open(data_bytes) | ||
|
||
|
||
def image_to_qimage(img): | ||
return ImageQt(img) |
Oops, something went wrong.