diff --git a/.gitignore b/.gitignore index 25e6f90..d501beb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__/filesManagement.cpython-39.pyc __pycache__/imageTreatment.cpython-39.pyc __pycache__/stitching.cpython-39.pyc __pycache__/exceptions.cpython-39.pyc +.DS_Store diff --git a/imageTreatment.py b/imageTreatment.py index 8e386d9..44344aa 100644 --- a/imageTreatment.py +++ b/imageTreatment.py @@ -35,7 +35,7 @@ def apply_low_pass_filter(self, image): fftimage = np.fft.fftshift(np.fft.fft2(image)) # Create low-pass filter. - lowPassFilter = self.low_Pass_Filter(image=image, sigmaFilter=1) + lowPassFilter = self.low_Pass_Filter(image=image, sigmaFilter=10) # Apply low-pass filters on respective cropped images. lowFFTimage = lowPassFilter * fftimage diff --git a/main.py b/main.py index 7c9e544..fa4627e 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from imageTreatment import * import tifffile as tiff -sourcePath = "/Users/valeriepineaunoel/Desktop/20220621-6umPolystyreneBeads-overlap10%-zoom2/LineCorrection" +sourcePath = "/Users/valeriepineaunoel/Desktop/20220621-6umPolystyreneBeads-overlap10%-zoom2/LineCorrection/IntensityCorrection" tileDimensions = [6, 4] #img = ImageTreatment(sourceDir=sourcePath) @@ -19,7 +19,7 @@ # #enveloppe = img.correct_intensity_envelop() -stitch = Stitching(sourceDir=sourcePath, tileD=tileDimensions, imageSize=[1024,512], isIntensityCorrection=True, isMirrored=True, isFlipped=False) +stitch = Stitching(sourceDir=sourcePath, tileD=tileDimensions, imageSize=[1024,512], isIntensityCorrection=False, isMirrored=True, isFlipped=False) stitchedImage = stitch.stitching_scrapbooking_allImages() plt.imshow(stitchedImage) plt.show() diff --git a/stitching.py b/stitching.py index 962edcc..5851be8 100644 --- a/stitching.py +++ b/stitching.py @@ -79,7 +79,10 @@ def calculate_shift_PCC(self, imageRef1, imageRef2) -> list: npimage1 = np.asarray(imageRef1) npimage2 = np.asarray(imageRef2) - reverseShift, error, disphase = phase_cross_correlation(reference_image=npimage1, moving_image=npimage2) + lownpImage1 = self.apply_low_pass_filter(image=npimage1) + lownpImage2 = self.apply_low_pass_filter(image=npimage2) + + reverseShift, error, disphase = phase_cross_correlation(reference_image=lownpImage1, moving_image=lownpImage2) # the sign of the x and/or y values of shift might need some change according to the flip or mirror state. if indexGiven: @@ -165,8 +168,8 @@ def estimate_shift(self, index:int, stitchingSide:str) -> list: movingIndex = index elif stitchingSide == "H": - referenceIndex = index - movingIndex = index+1 + referenceIndex = index-1 + movingIndex = index else: exc.define_variable(stitchingSide) @@ -184,9 +187,9 @@ def estimate_shift(self, index:int, stitchingSide:str) -> list: mbottom = 250 elif stitchingSide == "H": - rleft = self.imageSize[0] - 500 + rleft = self.imageSize[0] - 900 rtop = 0 - mright = 500 + mright = 900 mbottom = self.imageSize[1] else: @@ -202,18 +205,18 @@ def estimate_shift(self, index:int, stitchingSide:str) -> list: cropMoving = np.asarray(moving.crop((mleft, mtop, mright, mbottom))) # Apply a low-pass filter on the cropped images. - lowCropReference = self.apply_low_pass_filter(image=cropReference) - lowCropMoving = self.apply_low_pass_filter(image=cropMoving) + #lowCropReference = self.apply_low_pass_filter(image=cropReference) + #lowCropMoving = self.apply_low_pass_filter(image=cropMoving) # Estimates shift of low-passed cropped images. - shift = self.calculate_shift_PCC(imageRef1=lowCropReference, imageRef2=lowCropMoving) + shift = self.calculate_shift_PCC(imageRef1=cropReference, imageRef2=cropMoving) # Rescales the shift to make it correspond to the top-left coordinate (makes up for the crop). if stitchingSide == "V": shift[1] = shift[1] + (self.imageSize[1]-250) if stitchingSide == "H": - shift[0] = shift[0] + (self.imageSize[0]-500) + shift[0] = shift[0] + (self.imageSize[0]-900) return shift @@ -237,29 +240,22 @@ def stitching_scrapbooking_allImages(self): if x == 0: if y == 0: coordinates = self.calculate_coordinates_firstImage(background=tile) - #vCoordinates = [coordinates[0], coordinates[1]] - #hCoordinates = [coordinates[0], coordinates[1]] vCoordinates = coordinates hCoordinates = coordinates - print(f"COOR : {vCoordinates} and {hCoordinates}") else: shift = self.estimate_shift(index=i, stitchingSide="V") coordinates = [vCoordinates[0] + shift[0], vCoordinates[1] + shift[1]] - hCoordinates = [coordinates[0], coordinates[1]] - vCoordinates = [coordinates[0], coordinates[1]] + hCoordinates = coordinates + vCoordinates = coordinates # if not first image of the row, use the previous image to calcualte the shift else: - shift = self.calculate_shift_PCC(imageRef1=i-1, imageRef2=i) - print(f"shift last : {shift}") + shift = self.estimate_shift(index=i, stitchingSide="H") coordinates = [hCoordinates[0] + shift[0], hCoordinates[1] + shift[1]] - hCoordinates = [coordinates[0], coordinates[1]] + hCoordinates = coordinates image = fman.read_file(filePath=self.directory + "/" + self.files[i], imageType="PIL", mirror=self.isMirrored, flip=self.isFlipped) - print(coordinates) coords = coordinates - print(f"BEFORE PASTE : {coords}") - tile.paste(image, coordinates) - print(f"AFTER PASTE : {coords}") + tile.paste(image, (coordinates[0], coordinates[1])) i += 1