Skip to content

Commit

Permalink
canny
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdru committed Apr 17, 2017
1 parent d3fd6e0 commit fb1530e
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 508 deletions.
60 changes: 60 additions & 0 deletions controllers/segmentationController.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import matplotlib.pyplot as plt
import random
import time
import math
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '../..'))

from imageProcessor import colorModel, histogramService, imageService, imageComparison
from imageSegmentation import segmentation
from imageFilters import filters
from PyQt5.QtCore import QCoreApplication, QDir
from PyQt5.QtCore import QObject, pyqtSlot, QVariant #, QVariantList
from PyQt5.QtQml import QJSValue
Expand Down Expand Up @@ -88,3 +90,61 @@ def segRoberts(self, colorModelTag, currentImageChannelIndex, isOriginalImage,
text_file.write("Timer: {}: {}\n".format(colorModelTag, methodTimer))
img.save('{}/temp/processingImage.png'.format(self.appDir))
imageComparison.calculateImageDifference(colorModelTag, logFile)

@pyqtSlot(str, int, bool, float, float)
def segCanny(self, colorModelTag, currentImageChannelIndex, isOriginalImage,
amplifier, threshold):
"""
Canny
"""
img = self.imageService.openImage(isOriginalImage)
if img is None:
return

methodTimer = time.time()
if colorModelTag == 'RGB':
gaussianImg = img.copy()
gaussianDeviation = 1.0 ##############################################
gaussianFilterSize = math.floor(gaussianDeviation*3.0)
filters.gaussianBlur(colorModelTag, currentImageChannelIndex, gaussianImg.load(),
gaussianImg.size, (gaussianFilterSize, gaussianFilterSize))
segmentation.canny(colorModelTag, currentImageChannelIndex, img.load(), img.size,
gaussianImg.load(), amplifier, threshold)
methodTimer = time.time() - methodTimer
self.histogramService.saveHistogram(img=img, model=colorModelTag)
if colorModelTag == 'YUV':
colorModel.rgbToYuv(img.load(), img.size)
gaussianImg = img.copy()
gaussianDeviation = 1.0 ##############################################
gaussianFilterSize = math.floor(gaussianDeviation*3.0)
filters.gaussianBlur(colorModelTag, currentImageChannelIndex, gaussianImg.load(),
gaussianImg.size, (gaussianFilterSize, gaussianFilterSize))
segmentation.canny(colorModelTag, currentImageChannelIndex, img.load(), img.size,
gaussianImg.load(), amplifier, threshold)
methodTimer = time.time() - methodTimer
self.histogramService.saveHistogram(img=img, model=colorModelTag)
timerTemp = time.time()
colorModel.yuvToRgb(img.load(), img.size)
methodTimer = time.time() - methodTimer
if colorModelTag == 'HSL':
data = numpy.asarray(img, dtype="float")
data = colorModel.rgbToHsl(data)
gaussianData = numpy.copy(data)
gaussianDeviation = 1.0 ##############################################
gaussianFilterSize = math.floor(gaussianDeviation*3.0)
filters.gaussianBlur(colorModelTag, currentImageChannelIndex, gaussianData,
gaussianData.shape, (gaussianFilterSize, gaussianFilterSize))
segmentation.canny(colorModelTag, currentImageChannelIndex, gaussianData,
gaussianData.shape, gaussianData, amplifier, threshold)
methodTimer = time.time() - methodTimer
# data = numpy.copy(dataTemp)
self.histogramService.saveHistogram(data=data, model=colorModelTag)
timerTemp = time.time()
data = colorModel.hslToRgb(data)
img = Image.fromarray(numpy.asarray(numpy.clip(data, 0, 255), dtype="uint8"))
methodTimer = time.time() - timerTemp + methodTimer
logFile = '{}/temp/log/segRoberts.log'.format(self.appDir)
with open(logFile, "a+") as text_file:
text_file.write("Timer: {}: {}\n".format(colorModelTag, methodTimer))
img.save('{}/temp/processingImage.png'.format(self.appDir))
imageComparison.calculateImageDifference(colorModelTag, logFile)
Loading

0 comments on commit fb1530e

Please sign in to comment.