from fpdf import FPDF
import cv2

def equalize_histogram(image):
    img = cv2.imread(image)
    b, g, r = cv2.split(img)
    red = cv2.equalizeHist(r)
    green = cv2.equalizeHist(g)
    blue = cv2.equalizeHist(b)
    return cv2.merge((blue, green, red))



left_eye_image = "C:\\Users\\SUMANTH C\\Desktop\\sample\\10_left.jpeg"
right_eye_image = "C:\\Users\\SUMANTH C\\Desktop\\sample\\10_right.jpeg"
#ostu_thresholding(left_eye_image)
pdf = FPDF('P','mm','A4')
pdf.add_page('P')
pdf.set_font('Times', 'B', 24)
pdf.multi_cell(0, 14, "AUTOMATED DIABETIC RETINOPATHY DIAGNOSIS PORTAL",'C')
pdf.ln()
pdf.ln()
pdf.set_font('Times', 'B', 20)
pdf.multi_cell(0, 14, "RETINAL IMAGE SAMPLES FOR DOCTOR'S REFERENCE AFTER PREPROCESSING", 'C')
pdf.ln()
pdf.ln()
pdf.set_font('Times', 'B', 16)
pdf.multi_cell(0, 5, 'Patient ID: 1000', 'C')
pdf.ln()
pdf.ln()
pdf.set_font('Times', 'B', 16)
pdf.multi_cell(0, 5, 'Patient Name: HARISH', 'C')
pdf.ln()
pdf.ln()

pdf.add_page()
pdf.set_font('Times', 'B', 14)
pdf.multi_cell(0, 5, 'ORIGINAL RETINAL IMAGES')
pdf.ln()
pdf.ln()
pdf.multi_cell(0, 5, 'Left Eye Image')
pdf.ln()
pdf.ln()
pdf.image(left_eye_image,w=pdf.w/2.0, h=pdf.h/4.0)
pdf.ln()
pdf.ln()
pdf.multi_cell(0, 5, 'Right Eye Image')
pdf.ln()
pdf.ln()
pdf.image(right_eye_image,w=pdf.w/2.0, h=pdf.h/4.0)

pdf.add_page()
cv2.imwrite("samples/ostu_left.jpeg", equalize_histogram(left_eye_image))
cv2.imwrite("samples/ostu_right.jpeg", equalize_histogram(right_eye_image))
pdf.multi_cell(0, 5, 'RETINAL IMAGES ADAPTIVE HISTOGRAM EQUALIZATION')
pdf.ln()
pdf.ln()
pdf.multi_cell(0, 5, 'Left Eye Image')
pdf.ln()
pdf.ln()
pdf.image("samples/ostu_left.jpeg",w=pdf.w/2.0, h=pdf.h/4.0)
pdf.ln()
pdf.ln()
pdf.multi_cell(0, 5, 'Right Eye Image')
pdf.ln()
pdf.ln()
pdf.image("samples/ostu_right.jpeg",w=pdf.w/2.0, h=pdf.h/4.0)

pdf.output(("samples/eye_image.pdf"), 'F')
