Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion imageTreatment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the loading of images and the stitching of images in two different functions.

stitchedImage = stitch.stitching_scrapbooking_allImages()
plt.imshow(stitchedImage)
plt.show()
Expand Down
38 changes: 17 additions & 21 deletions stitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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

Expand Down