Beispiel #1
0
for filename in glob.glob('C:/Users/oezkan/HasanCan/RawImages/*.tif'):
    img = cv2.imread(filename, 0)
    image_list.append(img)

start_time1 = time.time()
for im in range(len(image_list)):

    # labeled signal
    _, labeled_crack = cv2.threshold(label_list[im], 245, 255,
                                     cv2.THRESH_BINARY)
    kernel_label = np.ones((3, 3), np.uint8)
    labeled_crack = cv2.dilate(labeled_crack, kernel_label, iterations=1)

    # apply fft for grid fingers
    img_fft = fft(image_list[im], mask_fft)

    # apply histogram equalization
    img_Eq = cv2.equalizeHist(img_fft)

    img_roi = createROI(img_Eq)

    #list of parameters for filters
    param_bl = [[9, 11], [100, 150]]  #changed
    param_gf = [[2, 4], [0.2, 0.4]]
    param_ad = [[10, 15], [(0.5, 0.5), (1., 1.)]]  #changed

    bl_class_result = ""
    ad_class_result = ""
    gf_class_result = ""
    wave_class_result = ""
Beispiel #2
0
'''
from fftFunction import fft
from adaptedFrangi import frangi 
from skimage import img_as_ubyte
import threading
import time
import numpy as np
import cv2
from matplotlib import pyplot as plt
from Vesselness2D import calculateVesselness2D

img_filtered_list = []

mask_fft = cv2.imread('C:/Users/oezkan/eclipse-workspace/thesis/filters/ModQ_EL_Poly-Bereket3.tif',0)
img_raw = cv2.imread('C:/Users/oezkan/HasanCan/RawImages/0000006214_bad_.tif',0)
img_fft = fft(img_raw, mask_fft) 
img_Eq = cv2.equalizeHist(img_fft)

class myThread (threading.Thread):
    def __init__(self, name, img_Eq, param1,param2,sigma_x,sigma_y):
        threading.Thread.__init__(self)
        self.name = name
        self.img_Eq = img_Eq
        self.param_1 = param1
        self.param_2 = param2
        self.sigmas = (sigma_x,sigma_y)
    def run(self):
        bilteralFiltering(self.name,self.img_Eq, self.param_1,self.param_2,sigmas)

# Define a function for the thread
def bilteralFiltering(threadName,img_Eq,param1,param2,sigma):
Beispiel #3
0
def perform_eCS_algorithm(img_in,
                          sigma_x=1.0,
                          sigma_y=1.0,
                          angle=0.0,
                          mask_fft=np.zeros((0))):
    """
    Perform eCS algorithm described in:
    Enhanced Crack Segmentation (eCS): A Reference Algorithm for Segmenting 
    Cracks in Multicrystalline Silicon Solar Cells

    Parameters
    ----------
    img_in : ndarray
        Input image.
    angle : float
        Rotation angle in degrees in counter-clockwise direction.
    sigma_x : float
        Gaussian filter sigma in x-direction
    sigma_y: float
        Gaussian filter sigma in y-direction
    mask_fft : ndarray
        mask for fft filtering to get rid of grid fingers

    Returns
    -------
    img_result : ndarray
        processed image

    """

    if (mask_fft.size != 0):
        img_in = fft(img_in, mask_fft)

    img_equalized = cv2.equalizeHist(img_in)
    img_roi = createROI(img_equalized)
    plt.figure()
    #plt.imshow(img_roi) - Good estimation of ROI. Implement in dataArtist
    img_smoothed = cv2.bilateralFilter(img_equalized, 3, 25, 25)

    if angle != 0.0:
        img_smoothed = rotate(img_smoothed,
                              angle,
                              resize=True,
                              preserve_range=True)

    img_result = img_as_ubyte(
        frangi(img_smoothed,
               sigma_x=sigma_x,
               sigma_y=sigma_y,
               beta1=0.5,
               beta2=0.05,
               black_ridges=True))

    if (sigma_x != sigma_y):
        img_y = img_as_ubyte(
            frangi(img_smoothed,
                   sigma_x=sigma_y,
                   sigma_y=sigma_x,
                   beta1=0.5,
                   beta2=0.05,
                   black_ridges=True))
        img_result = np.maximum(img_result, img_y)

    if angle != 0.0:  #Modified to handel rect img of diff sizes with np.shape
        w = img_result.shape[0]
        w_org = img_in.shape[0]  #changed to higt and width
        offset = (w - w_org) // 2
        h_org = img_in.shape[1]

        #img is rotated back, and scaled to right size
        img_result = rotate(img_result,
                            -angle,
                            resize=True,
                            preserve_range=True)[offset:offset + w_org,
                                                 offset:offset + h_org]

    img_result = img_result * img_roi

    return img_result.astype(
        'float32')  #does this need to be float32? can unit8?
    #wavelet = 'haar'
    #decompose to 2nd level coefficients
    [cA, (cH, cV, cD)] = pywt.dwt2(img, wavelet=wavelet)
    maxval = cA.max()
    cA = cA * (img.max() / maxval)
    return cA


imagePath = 'C:/Users/oezkan/HasanCan/RawImages/'
imagePathSave = 'C:/Users/Desktop/results/newResults/'
img = cv2.imread(imagePath + "0000007542_bad_.tif", 0)
mask_fft = cv2.imread(
    'C:/Users/oezkan/eclipse-workspace/thesis/filters/ModQ_EL_Poly-Bereket3.tif',
    0)

img = fft(img, mask_fft)

# apply histogram equalization
img_Eq = cv2.equalizeHist(img)

# mask is the ROI
mask = createROI(img_Eq)
#img  = cv2.pyrDown( img, (512,512))
#mask = cv2.pyrDown(mask, (512,512))

meanVal = img.mean()
img_maskIn = cv2.convertScaleAbs(numpy.where(mask == 0, meanVal, img))
mask_inv = cv2.convertScaleAbs(myInvertarr(mask))

# ----------------------------------------------------------------------------
Beispiel #5
0
    0)
mask_fft = cv2.imread(
    'C:/Users/oezkan/eclipse-workspace/thesis/filters/ModQ_EL_Poly-Bereket3.tif',
    0)
labeled_crack = cv2.imread(
    'C:/Users/oezkan/eclipse-workspace/thesis/filters/originalImages/0000331736_CrackLabel.tif'
)
maskRoi = cv2.imread(
    'C:/Users/oezkan/eclipse-workspace/thesis/filters/originalImages/0000331736_BusLabel.tif',
    0)

img_filtered = cv2.bilateralFilter(img_raw, 9, 75,
                                   75)  # I can also apply different filters

# apply fft for grid fingers
img_fft = fft(img_filtered, mask_fft)

MORPH = True

# labeled signal
_, labeled_crack = cv2.threshold(labeled_crack[:, :, 2], 127, 255,
                                 cv2.THRESH_BINARY)
kernel_label = np.ones((2, 2), np.uint8)
labeled_crack = cv2.dilate(labeled_crack, kernel_label, iterations=1)

#histogram equalization
img_fft = cv2.equalizeHist(img_fft)  # if not at the end I got a black image
img_fft = cv2.bilateralFilter(img_fft, 9, 75,
                              75)  # I can also apply different filters

#creating ROI for frangi