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 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 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)