def joinImagesH(images, bgcolor=128): totalWidth = sum([image.width for image in images]) maxHeight = max([image.height for image in images]) maxNChannels = max([image.nChannels for image in images]) if maxNChannels == 3: images = map(addFakeChannels, images) bgcolor = cv.ScalarAll(bgcolor) total = len(images) result = cv.CreateImage((totalWidth + total - 1, maxHeight), images[0].depth, images[0].nChannels) cv.Set(result, bgcolor) curW = 0 for index in xrange(len(images)): image = images[index] off = (maxHeight - image.height) / 2 cvext.copyTo(image, result, (curW, off), None) curW += image.width + 1 return result
def joinImagesV(images, bgcolor=128): totalHeight = sum([image.height for image in images]) maxWidth = max([image.width for image in images]) maxNChannels = max([image.nChannels for image in images]) if maxNChannels == 3: images = map(addFakeChannels, images) bgcolor = cv.ScalarAll(bgcolor) total = len(images) result = cv.CreateImage((maxWidth, totalHeight + total - 1), images[0].depth, images[0].nChannels) cv.Set(result, bgcolor) curH = 0 for index in xrange(len(images)): image = images[index] off = (maxWidth - image.width) / 2 cvext.copyTo(image, result, (off, curH), None) curH += image.height + 1 return result
n = image[y, x] / 127.5 - 1.0 lst.append(n) return lst def resizeNaive(image, size): result = cv.CreateImage(size, cv.IPL_DEPTH_8U, 1) cv.Resize(image, result, cv.CV_INTER_CUBIC) return result def resizeProp(image, (segW, segH)): result = cv.CreateImage((segW, segH), image.depth, image.nChannels) cv.Zero(result) if image.width <= segW and image.height <= segH: offW = (segW - image.width) / 2 offH = (segH - image.height) / 2 copyTo(image, result, (offW, offH), None) else: scaleW = float(segW) / float(image.width) newH = image.height * scaleW if newH <= segH: offH = (segH - newH) / 2.0 rect = (0, int(offH), segW, int(newH)) else: scaleH = float(segH) / float(image.height) newW = image.width * scaleH offW = (segW - newW) / 2.0 rect = (int(offW), 0, int(newW), segH) cv.SetImageROI(result, rect) cv.Resize(image, result, cv.CV_INTER_CUBIC) cv.ResetImageROI(result) return result
return lst def resizeNaive(image, size): result = cv.CreateImage(size, cv.IPL_DEPTH_8U, 1) cv.Resize(image, result, cv.CV_INTER_CUBIC) return result def resizeProp(image, (segW, segH)): result = cv.CreateImage((segW, segH), image.depth, image.nChannels) cv.Zero(result) if image.width <= segW and image.height <= segH: offW = (segW - image.width) / 2 offH = (segH - image.height) / 2 copyTo(image, result, (offW, offH), None) else: scaleW = float(segW) / float(image.width) newH = image.height * scaleW if newH <= segH: offH = (segH - newH) / 2.0 rect = (0, int(offH), segW, int(newH)) else: scaleH = float(segH) / float(image.height) newW = image.width * scaleH offW = (segW - newW) / 2.0 rect = (int(offW), 0, int(newW), segH) cv.SetImageROI(result, rect) cv.Resize(image, result, cv.CV_INTER_CUBIC) cv.ResetImageROI(result) return result