Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Error correction for circle detection, autocrop modification, report …
Browse files Browse the repository at this point in the history
…modification
  • Loading branch information
LP-CDF committed Feb 4, 2020
1 parent b8183b6 commit b7f3cf0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
18 changes: 9 additions & 9 deletions AMi_Image_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

def Citation():
print('''
Program written for in python3/PyQt5 by
Program written for python3/PyQt5 by
Ludovic Pecqueur
Laboratoire de Chimie des Processus Biologiques
Collège de France.
Expand Down Expand Up @@ -688,14 +688,14 @@ def buttonClicked(self):
ClassificationColor[self.classifications[well]]["text"]))


def LoadWellImage(self,path):

QtGui.QPixmapCache.clear()
label=QLabel(self)
pixmap=QPixmap(path)
#resize pixmap to size of the QscrollArea Temporary?
label.setPixmap(pixmap.scaled(860, 630, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
self.ImageViewer.setWidget(label)
# def LoadWellImage(self,path):
# ''' '''
# QtGui.QPixmapCache.clear()
# label=QLabel(self)
# pixmap=QPixmap(path)
# #resize pixmap to size of the QscrollArea Temporary?
# label.setPixmap(pixmap.scaled(860, 630, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
# self.ImageViewer.setWidget(label)

def open_image(self, path):
'''based on https://vincent-vande-vyvre.developpez.com/tutoriels/pyqt/manipulation-images/'''
Expand Down
2 changes: 1 addition & 1 deletion Check_Circle_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def DetectCircle(_file):
# Apply Hough transform on the blurred image.
detected_circles = cv2.HoughCircles(gray_blurred,
cv2.HOUGH_GRADIENT, 1, pref.minDistance , param1 = pref.param1,
param2 = pref.param1, minRadius =pref.minRadius, maxRadius = pref.maxRadius)
param2 = pref.param2, minRadius =pref.minRadius, maxRadius = pref.maxRadius)

euclidians=[]

Expand Down
37 changes: 24 additions & 13 deletions autocrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
python3 autocrop.py
Function is now called within GUI.
Can still be used as standalone
Can still be used as standalone script
"""

import os
Expand All @@ -31,19 +31,32 @@ def natural_sort_key(s):


def crop_ROI(image, output_dir, well):
x, y, r = find_best_circle(image)
r=r+100
cropped=image[y-r:y+r, x-r:x+r]
# print("CROPPED image size well %s "%well, cropped.shape)
x, y, r = find_best_circle(image)
if x==0 or y==0: #If No circle was detected
print("CROPPED image for well %s is empty, NOT SAVED"%well)
return False
r=r+20
Ymax, Xmax =image.shape[0], image.shape[1]
if y-r<0:ymin=0
else:ymin=y-r
if y+r>Ymax:ymax=Ymax
else:ymax=y+r
if x-r<0:xmin=0
else:xmin=x-r
if x+r>Xmax:xmax=Xmax
else: xmax=x+r
cropped=image[ymin:ymax, xmin:xmax]
# cropped=image[y-r:y+r, x-r:x+r]
# print("CROPPED image size well %s "%well, cropped.shape, "r=", r)

path=Path(output_dir).joinpath("cropped",well+".jpg")

#Only save images with bytes otherwise print error message
if cropped.shape[0] != 0 and cropped.shape[1] != 0:
cv2.imwrite(str(path), cropped)
print("well %s saved to %s"%(well, path))
# print("well %s saved to %s"%(well, path))
else:
# print("CROPPED image for well %s is empty"%well)
print("CROPPED image for well %s is empty, NOT SAVED"%well)
return False


Expand All @@ -58,9 +71,7 @@ def find_best_circle(image):
cv2.HOUGH_GRADIENT, 1, pref.minDistance, param1 = pref.param1,
param2 = pref.param2, minRadius = pref.minRadius, maxRadius = pref.maxRadius)

R = 0
X = 0
Y = 0
R, X, Y = 0, 0, 0
euclidians=[]

#Find detected circle with max radius closest to center of image, temporary bad solution
Expand All @@ -75,8 +86,8 @@ def find_best_circle(image):
R = int(i[1])
X = int(i[2])
Y = int(i[3])
# print("Rmax, X, Y ", R, X, Y)
# print("DISTANCES to image center ", euclidians, "MIN distance to image center", min(euclidians))
# if circles is not None:
# print("DISTANCES to image center for %s"%well, euclidians, "MIN distance to image center", min(euclidians))
del euclidians
return X,Y,R

Expand Down Expand Up @@ -106,7 +117,7 @@ def find_best_circle(image):
output=crop_ROI(img, directory, well)
if output is False:
errors +=1
error_list.append(well)
error_list.append(os.path.basename(_file))
del img, output

log=Path(directory).joinpath("cropped","autocrop.log")
Expand Down
2 changes: 2 additions & 0 deletions pdf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
2019
'''

__date__ = "04-02-2020"

class PDF(fpdf.FPDF):

def header(self):
Expand Down
10 changes: 5 additions & 5 deletions preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#Comment/uncomment the two lines below according to your need
keyboard_layout="qwerty"
#keyboard_layout="azerty"
# keyboard_layout="azerty"

#autoMARCO acceptance probability criterium
autoMARCO_threshold=0.60
Expand Down Expand Up @@ -58,8 +58,8 @@ class Shortcut():
class DetectCircle():
'''parameters for circle detection used in autocrop.py
and Check_Circle_detection.py'''
param1=35
param1=60
param2=25
minDistance=120
minRadius=100
maxRadius=300
minDistance=800
minRadius=250
maxRadius=400

0 comments on commit b7f3cf0

Please sign in to comment.