示例#1
0
def ELavOtsu(calibration_img_PATH):
    img = io.imread(calibration_img_PATH)
    img = rgb2gray(img)

    img = cv2.bilateralFilter(img, 9, 75, 75)

    img_roi = createROI(img)

    img_ROI = img_roi.copy()
    img_ROI[img_ROI == 0] = 255
    img_ROI = cv2.multiply(img, img_roi, dtype=cv2.CV_8U)  #.astype(np.uint8)
    th2, roi2 = cv2.threshold(img_ROI[img_ROI < 254], 0, 255,
                              cv2.THRESH_BINARY + cv2.THRESH_OTSU)

    return th2, img_roi
示例#2
0
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 = ""

    #apply the filters
    for index in range(0, 4, 1):

        if (index == 0):

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))

# ----------------------------------------------------------------------------

if wavelet == 'no':
    img_mask = img_maskIn
else:
    # save standard downscale image as comparison
    cv2.imwrite(imagePathSave + 'waveletcmp_downscale.tif',
                cv2.pyrDown(img_maskIn, (512, 512)))
示例#4
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?