Beispiel #1
0
def autoWhiteBalance(fl_input, fl_output, method = "automatic"):
    print("imageProcessing::autoWhiteBalance(fl_input, fl_output, method = 'automatic'")
    
    try:
        # Open the image object to be adjusted.
        img_pil_input = Image.open(fl_input)
        
        # Define the empty image object.
        img_pil_adj = None
        
        if method == "stretch": img_pil_adj = to_pil(cca.stretch(from_pil(img_pil_input)))
        elif method == "gray_world": img_pil_adj = to_pil(cca.gray_world(from_pil(img_pil_input)))
        elif method == "max_white": img_pil_adj = to_pil(cca.max_white(from_pil(img_pil_input)))
        elif method == "retinex": img_pil_adj = to_pil(cca.cca.retinex(from_pil(img_pil_input)))
        elif method == "retinex_adjusted": img_pil_adj = to_pil(cca.retinex_with_adjust(from_pil(img_pil_input)))
        elif method == "stdev_luminance": img_pil_adj = to_pil(cca.standard_deviation_and_luminance_weighted_gray_world(from_pil(img_pil_input)))
        elif method == "stdev_grey_world": img_pil_adj = to_pil(cca.standard_deviation_weighted_grey_world(from_pil(img_pil_input)))
        elif method == "luminance_weighted": img_pil_adj = to_pil(cca.luminance_weighted_gray_world(from_pil(img_pil_input)))
        elif method == "automatic": img_pil_adj = to_pil(cca.automatic_color_equalization(from_pil(img_pil_input)))
        
        # Save the adjusted image.
        img_pil_adj.save(fl_output)
        
        # Return the output file name.
        return(fl_output)
    except Exception as e:
        print("Error occured in imageProcessing::autoWhiteBalance(fl_input, fl_output, method = 'automatic'")
        print(str(e))
        error.ErrorMessageImageProcessing(details=str(e), show=True, language="en")
        return(None)
Beispiel #2
0
def applyEffectsACE_RETINEX(count, filename, file):
    print("{0} > apply ACE/RETINEX em {1}".format(count, filename))
    chaveF = filename[28:36]
    nomeParaSalvar = pastaSaida + chaveF + '_' + file
    img = Image.open(filename)
    img = to_pil(cca.automatic_color_equalization(from_pil(img)))
    img = to_pil(cca.retinex(from_pil(img)))
    img.save(nomeParaSalvar)
Beispiel #3
0
 def test_all(self):
     to_pil(stretch(from_pil(self.img)))
     to_pil(grey_world(from_pil(self.img)))
     to_pil(retinex(from_pil(self.img)))
     to_pil(max_white(from_pil(self.img)))
     to_pil(retinex_with_adjust(retinex(from_pil(self.img))))
     to_pil(
         standard_deviation_weighted_grey_world(from_pil(self.img), 20, 20))
     to_pil(
         standard_deviation_and_luminance_weighted_gray_world(
             from_pil(self.img), 20, 20))
     to_pil(luminance_weighted_gray_world(from_pil(self.img), 20, 20))
     to_pil(automatic_color_equalization(from_pil(self.img)))
Beispiel #4
0
    def color_balance(self, imgLabel, n_algorithm, image, displayed_image):
        # Check if images exists
        if not self.__images_exists():
            return
        # Choose algorithm and save original image
        orig_image = copy.deepcopy(image)
        if n_algorithm == 0:
            image.paste(ccu.to_pil(cca.max_white(ccu.from_pil(image))))
        elif n_algorithm == 1:
            image.paste(ccu.to_pil(cca.grey_world(ccu.from_pil(image))))
        elif n_algorithm == 2:
            image.paste(
                ccu.to_pil(
                    cca.automatic_color_equalization(ccu.from_pil(image))))

        self.__paste_image__(image, displayed_image, imgLabel)
        answer = tk.messagebox.askyesno("Changes prompt", "Apply changes?")
        # If no, restore image
        if not answer:
            image.paste(orig_image.copy())
            self.__paste_image__(image, displayed_image, imgLabel)
Beispiel #5
0
import colorcorrect.algorithm as cca
import numpy as np
import sys


def from_pil(pimg):
    pimg = pimg.convert(mode='RGB')
    nimg = np.array(pimg)[:]
    # nimg.flags.writeable = True
    return nimg


def to_pil(nimg):
    return Image.fromarray(np.uint8(nimg))


if __name__ == "__main__":
    img = Image.open(sys.argv[1])
    # img.show()
    to_pil(cca.stretch(from_pil(img)))
    to_pil(cca.grey_world(from_pil(img)))
    to_pil(cca.retinex(from_pil(img)))
    to_pil(cca.max_white(from_pil(img)))
    to_pil(cca.retinex_with_adjust(cca.retinex(from_pil(img))))
    to_pil(cca.standard_deviation_weighted_grey_world(from_pil(img), 20, 20))
    to_pil(
        cca.standard_deviation_and_luminance_weighted_gray_world(
            from_pil(img), 20, 20))
    to_pil(cca.luminance_weighted_gray_world(from_pil(img), 20, 20))
    to_pil(cca.automatic_color_equalization(from_pil(img)))
Beispiel #6
0
colcor_path = os.path.join(target_dir, 'colcor')

if not path.isdir(colcor_path):
    try:
        os.mkdir(colcor_path)
    except OSError:
        print("Creation of the directory %s failed" % colcor_path)
    else:
        print("Successfully created the directory %s " % colcor_path)

Iter = 0

print("Executing...")

for thisFile in os.listdir(target_dir):
    file_name = os.path.join(target_dir, thisFile)
    if os.path.isfile(file_name):
        file_name = os.path.join(target_dir, thisFile)

        Iter += 1
        print("\r" + str(Iter) + '/' + str(file_count), end='')

        img = Image.open(file_name)
        img = to_pil(automatic_color_equalization(from_pil(img)))
        basename = os.path.basename(file_name)
        abs_filename = colcor_path + '/' + basename
        img.save(abs_filename)

print("\nDone.")
Beispiel #7
0
def applyEffectsACE(count, filename, file):
    # print("{0} > apply ACE em {1}".format(count, pastaSaida + file))
    nomeParaSalvar = pastaSaida + file
    img = Image.open(filename)
    img = to_pil(cca.automatic_color_equalization(from_pil(img)))
    img.save(nomeParaSalvar)