redwankarimsony / project-tomato

9 stars 6 forks source link

Hi, I dont find the function "Contrast Limited Adaptive Histogram Equalization (CLAHE)"! Where is it? Please #4

Closed iris-mygh closed 1 year ago

redwankarimsony commented 1 year ago

Hi, Thank you for reaching out. We did not include the CLAHE method to the main pipeline. Rather we applied CLAHE on the whole dataset and made a separate instance so that we don't have to perform CLAHE everytime the image is loaded. However, I added the function to the repo in this link: enhancements.py

Please look for the function applyCLAHE. `

def applyCLAHE(image, display: bool = False):

    image_bw = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # The declaration of CLAHE
    # clipLimit -> Threshold for contrast limiting
    clahe = cv2.createCLAHE(clipLimit=5)
    final_img = clahe.apply(image_bw)  # + 30
    final_img = np.stack((final_img,) * 3, axis=-1)

    # Ordinary thresholding the same image
    _, ordinary_img = cv2.threshold(image_bw, 155, 255, cv2.THRESH_BINARY)

    if display:
        fig = plt.figure(figsize=(9, 3), dpi=300)
        rows, cols = 1, 3

        # Display the original image
        fig.add_subplot(rows, cols, 1)
        plt.imshow(image, cmap=plt.cm.bone);
        plt.axis('off')
        plt.title("Input Image")

        # Display the thresholded image
        fig.add_subplot(rows, cols, 2)
        plt.imshow(ordinary_img, cmap=plt.cm.gray);
        plt.axis('off')
        plt.title("Binary Thresholded Image")

        # Display the CLAHE processed image
        fig.add_subplot(rows, cols, 3)
        plt.imshow(final_img, cmap=plt.cm.gray)
        plt.axis('off')
        plt.title("CLAHE Image")
        plt.show()
    # print(final_img.shape)
    return final_img

`

iris-mygh commented 1 year ago

Hi, Thank you for reaching out. We did not include the CLAHE method to the main pipeline. Rather we applied CLAHE on the whole dataset and made a separate instance so that we don't have to perform CLAHE everytime the image is loaded. However, I added the function to the repo in this link: enhancements.py

Please look for the function applyCLAHE. `

def applyCLAHE(image, display: bool = False):

    image_bw = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # The declaration of CLAHE
    # clipLimit -> Threshold for contrast limiting
    clahe = cv2.createCLAHE(clipLimit=5)
    final_img = clahe.apply(image_bw)  # + 30
    final_img = np.stack((final_img,) * 3, axis=-1)

    # Ordinary thresholding the same image
    _, ordinary_img = cv2.threshold(image_bw, 155, 255, cv2.THRESH_BINARY)

    if display:
        fig = plt.figure(figsize=(9, 3), dpi=300)
        rows, cols = 1, 3

        # Display the original image
        fig.add_subplot(rows, cols, 1)
        plt.imshow(image, cmap=plt.cm.bone);
        plt.axis('off')
        plt.title("Input Image")

        # Display the thresholded image
        fig.add_subplot(rows, cols, 2)
        plt.imshow(ordinary_img, cmap=plt.cm.gray);
        plt.axis('off')
        plt.title("Binary Thresholded Image")

        # Display the CLAHE processed image
        fig.add_subplot(rows, cols, 3)
        plt.imshow(final_img, cmap=plt.cm.gray)
        plt.axis('off')
        plt.title("CLAHE Image")
        plt.show()
    # print(final_img.shape)
    return final_img

`

Thank you for responding. Let me further ask that:

1/ "PlantVillage-Tomato.zip" that I downloaded from https://data.mendeley.com/public-files/datasets/tywbtsjrjv/files/d5652a28-c1d8-4b76-97f3-72fb80f94efc/file_downloaded" has CLAHE applied?

2/ According to your article "Before applying CLAHE, the leaf image was converted from RGB color space to Hunter Lab color space" while I see the CLAHE function you provided is BGR to Gray color space. Which is correct for you?

3/ The article says "The intensity channel of the leaf image was divided into P ×Q regions" and "a value of 7 for both P and Q provided the best results.” I can't find where you have set P=Q=7 in the applyCLAHE function?

4/ In the preprocessing step, you apply CLAHE on the whole dataset. So I understand the steps you do correctly: 1- applyHistogramEqualization, 2-applyHEFFilter, 3- applyCLAHE, 4. train model (Data Augmentation during runtime).

5/ According to Ablation study of different components of the proposed pipeline (applied CLAHE, Augmentation, & Classifier Network with Accuracy 99.30). Can you provide this model? I want to test it and compare it with the model I created from the training results according to your instructions. (I just found: MobileNetV1_WithoutCLAHE_NoAug_WithoutDense_ValBest.h5, MobileNetV2_WithCLAHE_NoAug_WithoutDense_ValBest.h5 instead of what I expected is MobileNetV2_WithCLAHE_withAug_withDense_ValBest.h5)

I greatly appreciate your article and contribution. Thank you again