def sumImages(self): unification = Unification(self.firstDecoder.name, self.secondDecoder.name, 'L') firstImage, secondImage = unification.grayUnification() width, height = firstImage.shape[0], firstImage.shape[1] maxSum = float( numpy.amax( numpy.add(firstImage.astype(numpy.uint32), secondImage.astype(numpy.uint32)))) maxValue = float(numpy.iinfo(firstImage.dtype).max) scaleFactor = (maxSum - maxValue) / maxValue if maxSum > maxValue else 0 result = numpy.ones((height, width), numpy.uint8) for h in range(height): for w in range(width): pom = (firstImage[h, w] - (firstImage[h, w] * scaleFactor)) + ( secondImage[h, w] - (secondImage[h, w] * scaleFactor)) result[h, w] = numpy.ceil(pom) ImageHelper.Save(result, self.imageType, 'sum-gray-images', False, self.firstDecoder, self.secondDecoder) result = Commons.Normalization(firstImage, result) ImageHelper.Save(result, self.imageType, 'sum-gray-images', True, self.firstDecoder, self.secondDecoder)
def divideImages(self): print('Divide gray image {} with image {}'.format( self.firstDecoder.name, self.secondDecoder.name)) unification = Unification(self.firstDecoder.name, self.secondDecoder.name, 'L') firstImage, secondImage = unification.grayUnification() width, height = firstImage.shape[0], firstImage.shape[1] maxValue = float(numpy.iinfo(firstImage.dtype).max) maxSum = float( numpy.amax( numpy.add(firstImage.astype(numpy.uint32), secondImage.astype(numpy.uint32)))) scaleFactor = maxValue / maxSum result = numpy.ones((height, width), numpy.uint8) for h in range(height): for w in range(width): pom = (int(firstImage[h, w]) + int(secondImage[h, w])) * scaleFactor result[h, w] = math.ceil(pom) ImageHelper.Save(result, self.imageType, 'divide-gray-images', False, self.firstDecoder, self.secondDecoder) result = Commons.Normalization(firstImage, result) ImageHelper.Save(result, self.imageType, 'divide-gray-images', True, self.firstDecoder, self.secondDecoder)
def divideImages(self): print('Divide 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) sumR = float( numpy.amax( numpy.add(firstImage[:, :, 0].astype(numpy.uint32), secondImage[:, :, 0].astype(numpy.uint32)))) sumG = float( numpy.amax( numpy.add(firstImage[:, :, 1].astype(numpy.uint32), secondImage[:, :, 1].astype(numpy.uint32)))) sumB = float( numpy.amax( numpy.add(firstImage[:, :, 2].astype(numpy.uint32), secondImage[:, :, 2].astype(numpy.uint32)))) scaleR = maxValue / sumR scaleG = maxValue / sumG scaleB = maxValue / sumB result = numpy.ones((height, width, 3), numpy.uint8) for h in range(height): for w in range(width): R = (int(firstImage[h, w, 0]) + int(secondImage[h, w, 0])) * scaleR G = (int(firstImage[h, w, 1]) + int(secondImage[h, w, 1])) * scaleG B = (int(firstImage[h, w, 2]) + int(secondImage[h, w, 2])) * scaleB result[h, w, 0] = numpy.ceil(R) result[h, w, 1] = numpy.ceil(G) result[h, w, 2] = numpy.ceil(B) ImageHelper.Save(result, self.imageType, 'divide-color-images', False, self.firstDecoder, self.secondDecoder) result = Commons.Normalization(firstImage, result) ImageHelper.Save(result, self.imageType, 'divide-color-images', True, self.firstDecoder, self.secondDecoder)
def multiplyImages(self): print('Multiply gray image {} with image {}'.format( self.firstDecoder.name, self.secondDecoder.name)) unification = Unification(self.firstDecoder.name, self.secondDecoder.name, 'L') firstImage, secondImage = unification.grayUnification() width, height = firstImage.shape[0], firstImage.shape[1] maxValue = float(numpy.iinfo(firstImage.dtype).max) result = numpy.ones((height, width), numpy.uint8) for h in range(height): for w in range(width): pom = int(firstImage[h, w]) * int(secondImage[h, w]) / maxValue result[h, w] = pom ImageHelper.Save(result, self.imageType, 'multiply-gray-images', False, self.firstDecoder, self.secondDecoder) result = Commons.Normalization(firstImage, result) ImageHelper.Save(result, self.imageType, 'multiply-gray-images', True, self.firstDecoder, self.secondDecoder)
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)
def sumImages(self): print('Sum 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] maxSum = float( numpy.amax( numpy.add(firstImage.astype(numpy.uint32), secondImage.astype(numpy.uint32)))) maxValue = float(numpy.iinfo(firstImage.dtype).max) scaleFactor = (maxSum - maxValue) / maxValue if maxSum > maxValue else 0 result = numpy.ones((height, width, 3), numpy.uint8) for h in range(height): for w in range(width): R = (firstImage[h, w, 0] - (firstImage[h, w, 0] * scaleFactor)) + ( secondImage[h, w, 0] - (secondImage[h, w, 0] * scaleFactor)) G = (firstImage[h, w, 1] - (firstImage[h, w, 1] * scaleFactor)) + ( secondImage[h, w, 1] - (secondImage[h, w, 1] * scaleFactor)) B = (firstImage[h, w, 2] - (firstImage[h, w, 2] * scaleFactor)) + ( secondImage[h, w, 2] - (secondImage[h, w, 2] * scaleFactor)) result[h, w] = [numpy.ceil(R), numpy.ceil(G), numpy.ceil(B)] ImageHelper.Save(result, self.imageType, 'sum-color-images', False, self.firstDecoder, self.secondDecoder) result = Commons.Normalization(firstImage, result) ImageHelper.Save(result, self.imageType, 'sum-color-images', True, self.firstDecoder, self.secondDecoder)
def unificationModule(): unification = Unification('Resources/kobieta.png', 'Resources/zawody.png', "L") unification.geometricGray() unification.rasterGray()