예제 #1
0
파일: test.py 프로젝트: zenwerk/Pyxif
 def test_transplant2(self):
     """To use on server.
     Passes binary data to input,
     and passes io.BytesIO instance to output
     """
     o = io.BytesIO()
     pyxif.transplant(I1, I2, o)
     self.assertEqual(pyxif.load(I1), pyxif.load(o.getvalue()))
     try:
         i = Image.open(o)
         i._getexif()
     except:
         self.fail("'transplant' generated wrong file")
     finally:
         i.close()
예제 #2
0
파일: test.py 프로젝트: zenwerk/Pyxif
 def test_transplant2(self):
     """To use on server.
     Passes binary data to input,
     and passes io.BytesIO instance to output
     """
     o = io.BytesIO()
     pyxif.transplant(I1, I2, o)
     self.assertEqual(pyxif.load(I1), pyxif.load(o.getvalue()))
     try:
         i = Image.open(o)
         i._getexif()
     except:
         self.fail("'transplant' generated wrong file")
     finally:
         i.close()
예제 #3
0
def process_clahe(in_path,
                  tileGridSize,
                  grey=False,
                  out_path="",
                  clip_limit=2):
    """
    Appy CLAHE (contrast limited adaptive histogram equalization) method on an image
    for more information about CLAHE, see https://docs.opencv.org/3.1.0/d5/daf/tutorial_py_histogram_equalization.html

    Overwriting image will raise an error, as the initial image is needed to copy-past metadata
    :param in_path: input image
    :param tileGridSize: size of the "blocks" to apply local histogram equalization
    :param grey: if True, the image will be converted to grayscale
    :param out_path: output path, the folders must exists and the image extension must be valid
            by default, output will be saved as input_path/input_name_clahe.JPG
    :param clip_limit: contrast limit, used to avoid too much noise
    """
    if out_path == "":
        out_path = ".".join(in_path.split(".")[:-1]) + "_clahe.JPG"

    # read input
    print("Processing CLAHE method on " + in_path.split("/")[-1])
    img = cv.imread(in_path)

    # convert color to gray
    if grey: img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    # apply a median filter before clahe
    img = cv.medianBlur(img, 3)

    # create clahe object
    clahe = cv.createCLAHE(clipLimit=clip_limit,
                           tileGridSize=(tileGridSize, tileGridSize))  # CLAHE

    # apply CLAHE for each image channel, and then recreate the full image (only useful if gray==False)
    channels_ini = cv.split(img)
    channels_final = []
    for channel in channels_ini:
        # Apply CLAHE
        channels_final.append(clahe.apply(channel))
    img_final = cv.merge(channels_final)

    # save image and write metadata from initial file
    cv.imwrite(out_path, img_final)
    pyxif.transplant(in_path, out_path)
예제 #4
0
파일: test.py 프로젝트: zenwerk/Pyxif
    def test_transplant(self):
        pyxif.transplant(INPUT_FILE1, INPUT_FILE2, "transplant.jpg")
        exif_src = pyxif.load(INPUT_FILE1)
        img_src = pyxif.load(INPUT_FILE2)
        generated = pyxif.load("transplant.jpg")

        self.assertEqual(exif_src, generated)
        self.assertNotEqual(img_src, generated)
        try:
            i = Image.open("transplant.jpg")
            i._getexif()
        except:
            self.fail("'transplant' generated wrong file")
        finally:
            i.close()

        with self.assertRaises(ValueError):
            pyxif.transplant(NOEXIF_FILE, INPUT_FILE2, "foo.jpg")
예제 #5
0
파일: test.py 프로젝트: zenwerk/Pyxif
    def test_transplant(self):
        pyxif.transplant(INPUT_FILE1, INPUT_FILE2, "transplant.jpg")
        exif_src = pyxif.load(INPUT_FILE1)
        img_src = pyxif.load(INPUT_FILE2)
        generated = pyxif.load("transplant.jpg")

        self.assertEqual(exif_src, generated)
        self.assertNotEqual(img_src, generated)
        try:
            i = Image.open("transplant.jpg")
            i._getexif()
        except:
            self.fail("'transplant' generated wrong file")
        finally:
            i.close()

        with  self.assertRaises(ValueError):
            pyxif.transplant(NOEXIF_FILE, INPUT_FILE2, "foo.jpg")
예제 #6
0
def transplant_sample():
    pyxif.transplant(os.path.join("samples", "01.jpg"),
                     os.path.join("samples", "02.jpg"),
                     "transplant_sample.jpg")