Esempio n. 1
0
    def multiplyImages(self):
        print('Multiply color image {} with image {}'.format(
            self.firstDecoder.name, self.secondDecoder.name))
        unification = Unification(self.firstDecoder.name,
                                  self.secondDecoder.name, self.imageType)
        firstImage, secondImage = unification.colorUnification()
        width, height = firstImage.shape[0], firstImage.shape[1]

        maxValue = float(numpy.iinfo(firstImage.dtype).max)
        result = numpy.ones((height, width, 3), numpy.uint8)
        for h in range(height):
            for w in range(width):
                result[h, w, 0] = int(firstImage[h, w, 0]) * int(
                    secondImage[h, w, 0]) / maxValue
                result[h, w, 1] = int(firstImage[h, w, 1]) * int(
                    secondImage[h, w, 1]) / maxValue
                result[h, w, 2] = int(firstImage[h, w, 2]) * int(
                    secondImage[h, w, 2]) / maxValue

        ImageHelper.Save(result, self.imageType, 'multiply-color-images',
                         False, self.firstDecoder, self.secondDecoder)
        result = Commons.Normalization(firstImage, result)
        ImageHelper.Save(result, self.imageType, 'multiply-color-images', True,
                         self.firstDecoder, self.secondDecoder)
Esempio n. 2
0
    def blendImages(self, ratio):
        print('Blending gray image {} with image {} and ratio {}'.format(
            self.firstDecoder.name, self.secondDecoder.name, ratio))
        if ratio < 0 or ratio > 1.0:
            raise ValueError('ratio is wrong')

        unification = Unification(self.firstDecoder.name,
                                  self.secondDecoder.name, 'L')
        firstImage = unification.scaleUpGray(self.firstDecoder)
        secondImage = unification.scaleUpGray(self.secondDecoder)
        width, height = firstImage.shape[0], firstImage.shape[1]

        result = numpy.ones((height, width), numpy.uint8)
        for h in range(height):
            for w in range(width):
                pom = ratio * firstImage[h, w] + (1 - ratio) * secondImage[h,
                                                                           w]
                result[h, w] = pom

        ImageHelper.Save(result, self.imageType, 'blend-gray-images', False,
                         self.firstDecoder, None, ratio)
Esempio n. 3
0
    def logarithm(self):
        print('Logarithm color image {}'.format(self.firstDecoder.name))
        height, width = self.firstDecoder.height, self.firstDecoder.width
        image = self.firstDecoder.getPixels()

        maxValue = float(numpy.iinfo(image.dtype).max)
        maxR = numpy.amax(image[:, :, 0])
        maxG = numpy.amax(image[:, :, 1])
        maxB = numpy.amax(image[:, :, 2])
        result = numpy.ones((height, width, 3), numpy.uint32)
        for h in range(height):
            for w in range(width):
                result[h, w, 0] = maxValue * (math.log10(1 + image[h, w, 0]) /
                                              math.log10(1 + maxR))
                result[h, w, 1] = maxValue * (math.log10(1 + image[h, w, 1]) /
                                              math.log10(1 + maxG))
                result[h, w, 2] = maxValue * (math.log10(1 + image[h, w, 2]) /
                                              math.log10(1 + maxB))

        ImageHelper.Save(result.astype(numpy.uint8), self.imageType,
                         'logarithm-color', False, self.firstDecoder)
Esempio n. 4
0
 def getAdaptiveThreshold(self, maxVal, blockSize, c):
     outputAdaptive = cv2.adaptiveThreshold(self.image, maxVal,
                                            cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                            cv2.THRESH_BINARY, blockSize, c)
     ImageHelper.showImage('Adaptive Thresh', outputAdaptive)
Esempio n. 5
0
 def preProcessGrayScale(self):
     cv2.equalizeHist(self.image, self.image)
     ImageHelper.showImage('Normalized', self.image)
     pass
    def doStuff(self, fileName):
        pass
        hsvImg = cv2.cvtColor(self.image, cv2.COLOR_RGB2HSV)
        h, s, v = cv2.split(hsvImg)

        if FeatureDebug.DEBUG_DRAW_TRUTH:
            from db import Database as db
            self.db = db
            self.image = self.__drawTruth__(self.image, fileName)

        processedH = self.image.copy()
        processedS = self.image.copy()

        _, h_thresh = cv2.threshold(h, 60, 255, cv2.THRESH_BINARY_INV)
        _, s_threshed = cv2.threshold(s, 50, 60, cv2.THRESH_BINARY)

        #apply mask to image
        processedH = cv2.bitwise_and(self.image, self.image, mask=h_thresh)
        processedS = cv2.bitwise_and(self.image, self.image, mask=s_threshed)

        ImageHelper.showImage('Original', self.image)
        # ImageHelper.showImage('HSV', hsvImg)
        ImageHelper.showImage('H', h)
        ImageHelper.showImage('S', s)
        ImageHelper.showImage('V', v)
        ImageHelper.showImage('h_threshed', h_thresh)
        # ImageHelper.showImage('h_mask_threshed', self.__drawTruth__(processedH, fileName))
        ImageHelper.showImage('s_threshed', s_threshed)
        # ImageHelper.showImage('s_mask_threshed', self.__drawTruth__(processedS, fileName))

        return processedH