def registerThermalAndColorImages()

in src/image_registration/ir_to_rgb_registration/image_registration.py [0:0]


def registerThermalAndColorImages(file, fileOut, folder, displayResults=False):
    
    hotspots = []

    with open(file, 'r') as csvfile:
        reader = csv.reader(csvfile, delimiter=',')

        # header row
        headers = next(reader, None)

        for row in reader:
            hotspots.append(row)

    for i in range(0, len(hotspots)):

        hotspot = hotspots[i]

        fileIR = folder + hotspot[2]
        fileRGB = folder + hotspot[4]
        x = float(hotspot[5])
        y = float(hotspot[6])

        print('%d:\t%s\n\t%s' %(i, fileIR, fileRGB))

        thumb = [-1, -1, -1, -1]

        # Read the images to be aligned
        img, img16bit = imreadIR(fileIR)

        if (img is None):
            print('\nnot found\n')
            hotspots[i][7:11] = thumb
            continue

        imgRef =  cv2.imread(fileRGB)

        if (imgRef is None):
            print('\nnot found\n')
            hotspots[i][7:11] = thumb
            continue

        # omcpute transform
        ret, transform = computeTransform(imgRef, img)
    
        if (ret):
            pt = [x, y]
            ptWarped = np.round(warpPoint(pt, transform))

            thumb = [int(ptWarped[0]-256), int(ptWarped[1]-256), int(ptWarped[0]+256), int(ptWarped[1]+256)]

            if (displayResults):
                # warp IR image
                imgWarped = cv2.warpPerspective(img, transform, (imgRef.shape[1], imgRef.shape[0]))
                #img16bitWarped = cv2.warpPerspective(img16bit, transform, (imgRef.shape[1], imgRef.shape[0]))

                # display everything
                plt.figure()
                plt.subplot(2, 2, 1)
                plt.imshow(img, cmap='gray')
                plt.plot(pt[0],pt[1],color='red', marker='o')
                plt.title("Orig IR")

                plt.subplot(2, 2, 2)
                plt.imshow(imgWarped, cmap='gray')
                plt.plot(ptWarped[0],ptWarped[1],color='red', marker='o')
                plt.title("Aligned IR")

                plt.subplot(2, 2, 3)
                plt.imshow(cv2.cvtColor(imgRef, cv2.COLOR_BGR2RGB))
                plt.plot(ptWarped[0],ptWarped[1],color='red', marker='o')
                plt.title("Orig RGB")

                plt.subplot(2, 2, 4)  
                thumb = imgRef[thumb[1]:thumb[3], thumb[0]:thumb[2],:]
                plt.imshow(cv2.cvtColor(thumb, cv2.COLOR_BGR2RGB))
                plt.title("Thumb RGB")

                plt.show()
        else:

            if (displayResults):
                plt.figure()
                plt.subplot(1, 2, 1)
                plt.imshow(img, cmap='gray')
                plt.title("Orig IR")

                plt.subplot(1, 2, 2)
                plt.imshow(cv2.cvtColor(imgRef, cv2.COLOR_BGR2RGB))
                plt.title("Orig RGB")

                plt.show()

            print('alignment failed!')

        hotspots[i][7:11] = thumb

    with open(fileOut, 'w', newline='') as csvfile:
        writer = csv.writer(csvfile, delimiter=',')

        writer.writerow(headers)
        for i in range(0, len(hotspots)): 
            
            writer.writerow(hotspots[i])