Example #1
0
    def decensor_all_images_in_folder(self):
        # load model once at beginning and reuse same model
        # self.load_model()
        color_dir = self.args.decensor_input_path
        file_names = os.listdir(color_dir)

        input_dir = self.args.decensor_input_path
        output_dir = self.args.decensor_output_path

        # Change False to True before release --> file.check_file( input_dir, output_dir, True)
        file_names, self.files_removed = file.check_file(input_dir, output_dir, False)

        # convert all images into np arrays and put them in a list
        for file_name in file_names:
            color_file_path = os.path.join(color_dir, file_name)
            color_bn, color_ext = os.path.splitext(file_name)
            if os.path.isfile(color_file_path) and color_ext.casefold() == ".png":
                print("--------------------------------------------------------------------------")
                print("Decensoring the image {}".format(color_file_path))
                try:
                    colored_img = Image.open(color_file_path)
                except:
                    print("Cannot identify image file (" + str(color_file_path)+")")
                    self.files_removed.append((color_file_path, 3))
                    # incase of abnormal file format change (ex : text.txt -> text.png)
                    continue

                # if we are doing a mosaic decensor
                if self.is_mosaic:
                    # get the original file that hasn't been colored
                    ori_dir = self.args.decensor_input_original_path
                    # since the original image might not be a png, test multiple file formats
                    valid_formats = {".png", ".jpg", ".jpeg"}
                    for test_file_name in os.listdir(ori_dir):
                        test_bn, test_ext = os.path.splitext(test_file_name)
                        if (test_bn == color_bn) and (test_ext.casefold() in valid_formats):
                            ori_file_path = os.path.join(ori_dir, test_file_name)
                            ori_img = Image.open(ori_file_path)
                            # colored_img.show()
                            self.decensor_image(ori_img, colored_img, file_name)
                            break
                    else:  # for...else, i.e if the loop finished without encountering break
                        print("Corresponding original, uncolored image not found in {}".format(color_file_path))
                        print("Check if it exists and is in the PNG or JPG format.")
                else:
                    self.decensor_image(colored_img, colored_img, file_name)
            else:
                print("--------------------------------------------------------------------------")
                print("Iregular file deteced : "+str(color_file_path))
        print("--------------------------------------------------------------------------")
        if(self.files_removed is not None):
            file.error_messages(None, self.files_removed)
        if(self.args.autoclose == False):
            input("\nPress anything to end...")
Example #2
0
    def decensor_all_images_in_folder(self):
        #load model once at beginning and reuse same model
        if not self.warm_up:
            # incase of running by source code
            self.load_model()

        input_color_dir = self.decensor_input_path
        file_names = os.listdir(input_color_dir)

        input_dir = self.decensor_input_path
        output_dir = self.decensor_output_path

        # Change False to True before release --> file.check_file(input_dir, output_dir, True)
        # self.signals.update_progress_LABEL.emit("file.check_file()", "Checking image files and directory...")
        self.signals.insertText_progressCursor.emit(
            "Checking image files and directory...\n")

        file_names, self.files_removed = file.check_file(
            input_dir, output_dir, False)

        # self.signals.total_ProgressBar_update_MAX_VALUE.emit("set total progress bar MaxValue : "+str(len(file_names)),len(file_names))
        '''
        print("set total progress bar MaxValue : "+str(len(file_names)))
        self.signals.update_ProgressBar_MAX_VALUE.emit(len(file_names))
        '''
        self.signals.insertText_progressCursor.emit(
            "Decensoring {} image files\n".format(len(file_names)))

        #convert all images into np arrays and put them in a list
        for n, file_name in enumerate(file_names, start=1):
            # self.signals.total_ProgressBar_update_VALUE.emit("Decensoring {} / {}".format(n, len(file_names)), n)
            '''
            self.update_ProgressBar_SET_VALUE.emit(n)
            print("Decensoring {} / {}".format(n, len(file_names)))
            '''
            self.signals.insertText_progressCursor.emit(
                "Decensoring image file : {}\n".format(file_name))

            # signal progress bar value == masks decensored on image ,
            # e.g) sample image : 17
            # self.signals.signal_ProgressBar_update_VALUE.emit("reset value", 0) # set to 0 for every image at start
            # self.signals.update_progress_LABEL.emit("for-loop, \"for file_name in file_names:\"","Decensoring : "+str(file_name))

            color_file_path = os.path.join(input_color_dir, file_name)
            color_basename, color_ext = os.path.splitext(file_name)
            if os.path.isfile(
                    color_file_path) and color_ext.casefold() == ".png":
                print(
                    "--------------------------------------------------------------------------"
                )
                print("Decensoring the image {}\n".format(color_file_path))
                try:
                    colored_img = Image.open(color_file_path)
                except:
                    print("Cannot identify image file (" +
                          str(color_file_path) + ")")
                    self.files_removed.append((color_file_path, 3))
                    # incase of abnormal file format change (ex : text.txt -> text.png)
                    continue

                #if we are doing a mosaic decensor
                if self.is_mosaic:
                    #get the original file that hasn't been colored
                    ori_dir = self.decensor_input_original_path
                    test_file_names = os.listdir(ori_dir)
                    #since the original image might not be a png, test multiple file formats
                    valid_formats = {".png", ".jpg", ".jpeg"}
                    for test_file_name in test_file_names:
                        test_basename, test_ext = os.path.splitext(
                            test_file_name)
                        if (test_basename
                                == color_basename) and (test_ext.casefold()
                                                        in valid_formats):
                            ori_file_path = os.path.join(
                                ori_dir, test_file_name)
                            ori_img = Image.open(ori_file_path)
                            # colored_img.show()
                            self.decensor_image_variations(
                                ori_img, colored_img, file_name)
                            break
                    else:  #for...else, i.e if the loop finished without encountering break
                        print(
                            "Corresponding original, uncolored image not found in {}"
                            .format(color_file_path))
                        print(
                            "Check if it exists and is in the PNG or JPG format."
                        )
                        self.signals.insertText_progressCursor.emit(
                            "Corresponding original, uncolored image not found in {}\n"
                            .format(color_file_path))
                        self.signals.insertText_progressCursor.emit(
                            "Check if it exists and is in the PNG or JPG format.\n"
                        )
                #if we are doing a bar decensor
                else:
                    self.decensor_image_variations(colored_img, colored_img,
                                                   file_name)
            else:
                print(
                    "--------------------------------------------------------------------------"
                )
                print("Image can't be found: " + str(color_file_path))
                self.signals.insertText_progressCursor.emit(
                    "Image can't be found: " + str(color_file_path) + "\n")

        print(
            "--------------------------------------------------------------------------"
        )
        if self.files_removed is not None:
            file.error_messages(None, self.files_removed)
        print("\nDecensoring complete!")

        #unload model to prevent memory issues
        # self.signals.update_progress_LABEL.emit("finished", "Decensoring complete! Close this window and reopen DCP to start a new session.")
        self.signals.insertText_progressCursor.emit(
            "\nDecensoring complete! remove decensored file before decensoring again not to overwrite"
        )
        self.signals.update_decensorButton_Enabled.emit(True)
        tf.compat.v1.reset_default_graph()
Example #3
0
    def decensor_all_images_in_folder(self):
        #load model once at beginning and reuse same model
        self.load_model()

        input_color_dir = self.decensor_input_path
        file_names = os.listdir(input_color_dir)

        input_dir = self.decensor_input_path
        output_dir = self.decensor_output_path

        # Change False to True before release --> file.check_file(input_dir, output_dir, True)
        file_names, self.files_removed = file.check_file(
            input_dir, output_dir, False)

        #convert all images into np arrays and put them in a list
        for file_name in file_names:
            color_file_path = os.path.join(input_color_dir, file_name)
            color_basename, color_ext = os.path.splitext(file_name)
            if os.path.isfile(
                    color_file_path) and color_ext.casefold() == ".png":
                self.custom_print(
                    "--------------------------------------------------------------------------"
                )
                self.custom_print(
                    "Decensoring the image {}".format(color_file_path))
                try:
                    colored_img = Image.open(color_file_path)
                except:
                    self.custom_print("Cannot identify image file (" +
                                      str(color_file_path) + ")")
                    self.files_removed.append((color_file_path, 3))
                    # incase of abnormal file format change (ex : text.txt -> text.png)
                    continue

                #if we are doing a mosaic decensor
                if self.is_mosaic:
                    #get the original file that hasn't been colored
                    ori_dir = self.decensor_input_original_path
                    test_file_names = os.listdir(ori_dir)
                    #since the original image might not be a png, test multiple file formats
                    valid_formats = {".png", ".jpg", ".jpeg"}
                    for test_file_name in test_file_names:
                        test_basename, test_ext = os.path.splitext(
                            test_file_name)
                        if (test_basename
                                == color_basename) and (test_ext.casefold()
                                                        in valid_formats):
                            ori_file_path = os.path.join(
                                ori_dir, test_file_name)
                            ori_img = Image.open(ori_file_path)
                            # colored_img.show()
                            self.decensor_image_variations(
                                ori_img, colored_img, file_name)
                            break
                    else:  #for...else, i.e if the loop finished without encountering break
                        self.custom_print(
                            "Corresponding original, uncolored image not found in {}"
                            .format(color_file_path))
                        self.custom_print(
                            "Check if it exists and is in the PNG or JPG format."
                        )
                #if we are doing a bar decensor
                else:
                    self.decensor_image_variations(colored_img, colored_img,
                                                   file_name)
            else:
                self.custom_print(
                    "--------------------------------------------------------------------------"
                )
                self.custom_print("Image can't be found: " +
                                  str(color_file_path))
        self.custom_print(
            "--------------------------------------------------------------------------"
        )
        if self.files_removed is not None:
            file.error_messages(None, self.files_removed)
        self.custom_print("\nDecensoring complete!")

        #unload model to prevent memory issues
        tf.reset_default_graph()