Exemplo n.º 1
0
def main():
    print("Initializing ...")
    working_directory=sys.argv[1]
    if working_directory[-1]=="/":
        working_directory=working_directory[0:-1]
    source_csv=working_directory+"/input.csv"
    csv_exportname=working_directory+"/output.csv"
    pixel_range=(0,255)
    mask_threshold=255/2
    full_data=[["id","temp","raw","x","y"]]
    i=1
    with open(source_csv) as csv_file:
        csv_reader=csv.DictReader(csv_file)
        for frame in csv_reader:
            # say what we're doing
            print("Starting image "+str(i), end="")
            sys.stdout.flush()
            # process each entry in csv
            # csv format: id, image name, mask name, max temp, min temp, crop details (2 points)
            image_filename=working_directory+"/"+frame["image_name"]
            mask_filename=working_directory+"/"+frame["mask_name"]
            temp_range=(float(frame["max_temp"]),float(frame["min_temp"]))
            cropsize=(int(frame["topleft_x"]), int(frame["topleft_y"]),
                      int(frame["bottomright_x"])-int(frame["topleft_x"]),
                      int(frame["bottomright_y"])-int(frame["topleft_y"]))
            start_coords=(int(frame["topleft_x"]), int(frame["topleft_y"]))
            id=frame["id"]
            # load thermal image
            main_image=ndimage.imread(image_filename,flatten=True)
            cropped_image=imaging.crop(cropsize,main_image)

            # process mask to boolean
            mask_image=ndimage.imread(mask_filename,flatten=True)
            cropped_mask=imaging.crop(cropsize,mask_image)
            cropped_mask=cropped_mask[:,:] < mask_threshold
            if not imaging.verify_mask(main_image, mask_image):
                raise Exception("Mask does not fit image")

            # make the dataset for this image
            frame_data=thermal.thermal_image_to_dataset(cropped_image, temp_range, pixel_range, id, cropped_mask, start_coords)
            full_data.extend(frame_data)
            i+=1
            print("done!")

    # save the dataset
    print("Saving csv ...")
    with open(csv_exportname, mode="w", newline="") as file:
        write_obj=csv.writer(file)
        write_obj.writerows(full_data)
    print("Completed!")
Exemplo n.º 2
0
 def test_crop3(self):
     test_image = np.array([[1, 2], [3, 4]])
     test_params = (0, 0, 2, 1)
     expected_cropped_image = np.array([[1]])
     actual_cropped_image = imaging.crop(test_params, test_image)
     result = np.array_equal(actual_cropped_image, expected_cropped_image)
     self.assertFalse(result)
Exemplo n.º 3
0
 def test_crop1(self):
     test_image = np.array([[1, 2], [3, 4]])
     test_params = (1, 1, 1, 1)
     expected_cropped_image = np.array([[4]])
     actual_cropped_image = imaging.crop(test_params, test_image)
     result = np.array_equal(actual_cropped_image, expected_cropped_image)
     self.assertTrue(result)
Exemplo n.º 4
0
def main():
    image_filename = sys.argv[1]

    csv_exportname = sys.argv[2]
    cropsize = (10, 30, 290, 180)  #x offset, y offset, x size, y size
    temp_range = (17.0, 12.9)
    pixel_range = (0, 255)
    mask_threshold = 255 / 2

    # load thermal image
    main_image = ndimage.imread(image_filename, flatten=True)

    if len(sys.argv) == 4:
        mask_filename = sys.argv[3]
        mask_image = ndimage.imread(mask_filename, flatten=True)
        cropped_mask = imaging.crop(cropsize, mask_image)
        cropped_mask = cropped_mask[:, :] < mask_threshold
        if not imaging.verify_mask(main_image, mask_image):
            raise Exception("Mask does not fit image")
        if config.debug:
            plt.imshow(cropped_mask)
            plt.show()
    else:
        cropped_mask = None

    cropped_image = imaging.crop(cropsize, main_image)

    if (config.debug):
        plt.imshow(cropped_image)
        plt.show()

    test_datset = thermal.thermal_image_to_dataset(cropped_image, temp_range,
                                                   pixel_range, "1",
                                                   cropped_mask)

    with open(csv_exportname, mode="w", newline="") as file:
        write_obj = csv.writer(file)
        write_obj.writerows(test_datset)
Exemplo n.º 5
0
def main():
    print("Initializing ...")
    if len(sys.argv) > 1:  # check if there's a folder argument
        gui_enabled = False
        working_directory = sys.argv[1]
        if working_directory[-1] == "/":
            working_directory = working_directory[0:-1]
        source_csv = working_directory + "/input_batch.csv"
        csv_exportname = working_directory + "/output.csv"
    else:
        gui_enabled = True
        working_directory = easygui.diropenbox("Select image folder")
        source_csv = working_directory + "/input_batch.csv"
        csv_exportname = easygui.filesavebox("Save resulting CSV")
    pixel_range = (0, 255)
    mask_threshold = 255 / 2
    full_data = [["id", "temp", "raw", "x", "y"]]
    i = 1
    with open(source_csv) as csv_file:
        csv_reader = csv.DictReader(csv_file)
        for frame in csv_reader:

            # say what we're doing

            print("Starting image " + str(i) + " (" + frame["id"] + ")",
                  end="")
            sys.stdout.flush()

            # process each entry in csv
            # csv format: id, image name, mask name, max temp, min temp,
            # crop details (2 x-y coordinates)
            image_filename = working_directory + "/" + frame["image_name"]
            mask_filename = working_directory + "/" + frame["mask_name"]
            temp_range = (float(frame["max_temp"]), float(frame["min_temp"]))
            id = frame["id"]

            # load thermal image
            main_image = ndimage.imread(image_filename, flatten=True)

            # process mask to boolean
            mask_image = ndimage.imread(mask_filename, flatten=True)
            mask_image = mask_image[:, :] < mask_threshold
            if not imaging.verify_mask(main_image, mask_image):
                raise Exception("Mask does not fit image")

            # automatic vector crop
            crop_params = imaging.mask_crop_size(mask_image)
            cropped_image = imaging.crop(crop_params, main_image)
            cropped_mask = imaging.crop(crop_params, mask_image)

            # make the dataset for this image
            frame_data = thermal.thermal_image_to_dataset(
                cropped_image, temp_range, pixel_range, id, cropped_mask,
                (crop_params[0], crop_params[1]))
            full_data.extend(frame_data)
            i += 1
            print("done!")

    # save the dataset
    print("Saving csv ...")
    with open(csv_exportname, mode="w", newline="") as file:
        write_obj = csv.writer(file)
        write_obj.writerows(full_data)
    print("Completed!")
    if gui_enabled: easygui.textbox("Processing complete!")