import matplotlib.pyplot as plt

kernel1 = np.ones((3, 3), np.uint8)

img1 = cv2.imread(
    '/home/suryo/Image_Processing_Exercises/indictools-prep/resources/Kandanuword.jpg',
    0)
words_temp = np.zeros(img1.shape[:2], np.uint8)
print img1.shape[:2]
difference_values = []
clipped_values = []
clipped_local_minima = []

cv2.imshow('Original Image', img1)

prep_img1 = prep2.binary_img(img1)
cv2.imshow('Binarized Image', prep_img1)

dilate1 = cv2.dilate(prep_img1, kernel1, iterations=1)
cv2.imshow('Dilated', dilate1)

contours, hierarchy = cv2.findContours(dilate1, cv2.RETR_TREE,
                                       cv2.CHAIN_APPROX_SIMPLE)
for xx in contours:
    cv2.drawContours(words_temp, [xx], -1, (255, 255, 255), -1)
cv2.imshow('Contours from Dilated', words_temp)

contours, hierarchy = cv2.findContours(words_temp, cv2.RETR_TREE,
                                       cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
    x, y, w, h = cv2.boundingRect(c)
"""

import cv2
import prep2
import numpy as np
kernel1 = np.ones((2, 2), np.uint8)
kernel2 = np.ones((1, 1), np.uint8)

all_heights = []
img = cv2.imread(
    '/home/suryo/Image_Processing_Exercises/indictools-prep/resources/2.jpg',
    0)
cv2.imshow('Output0', img)
words_temp = np.zeros(img.shape[:2], np.uint8)

binary = prep2.binary_img(img)

sobelx = cv2.Sobel(binary, cv2.CV_64F, 1, 0, ksize=5)
cv2.imshow('sobel', sobelx)

abs_sobel64f = np.absolute(sobelx)
sobel_8u = np.uint8(abs_sobel64f)

dilate_sobel = cv2.dilate(sobel_8u, kernel2, iterations=1)
cv2.imshow('dilate sobel', dilate_sobel)

opening = cv2.morphologyEx(dilate_sobel, cv2.MORPH_OPEN, kernel1)
cv2.imshow('open sobel', opening)

dilation = cv2.dilate(binary, kernel2, iterations=1)
erosion = cv2.dilate(dilation, kernel2, iterations=1)
@author: suryo
"""


import cv2
import prep2
import numpy as np
kernel1 = np.ones((2,3),np.uint8)
kernel2 = np.ones((1,1),np.uint8)

all_heights = [] 
img = cv2.imread('/home/suryo/Image_Processing_Exercises/indictools-prep/resources/hi.png',0)
cv2.imshow('Output0',img)
words_temp = np.zeros(img.shape[:2],np.uint8)

binary = prep2.binary_img(img)

dilation = cv2.dilate(binary,kernel1,iterations = 1)
erosion = cv2.dilate(dilation,kernel1,iterations = 1)

cv2.imshow('d',erosion)

contours, hierarchy = cv2.findContours(erosion,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

for xx in contours:
    cv2.drawContours(words_temp,[xx],-1,(255,255,255),-1)
cv2.imshow('Outputtemp0',words_temp)
    
contours, hierarchy = cv2.findContours(words_temp,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
    x,y,w,h = cv2.boundingRect(c)
import prep2
import numpy as np
import matplotlib.pyplot as plt
kernel1 = np.ones((3,3),np.uint8)


img1 = cv2.imread('/home/suryo/Image_Processing_Exercises/indictools-prep/resources/Kandanuword.jpg',0)
words_temp = np.zeros(img1.shape[:2],np.uint8)
print img1.shape[:2]
difference_values =[]
clipped_values= []
clipped_local_minima = []

cv2.imshow('Original Image',img1)

prep_img1 = prep2.binary_img(img1)
cv2.imshow('Binarized Image',prep_img1)

dilate1 = cv2.dilate(prep_img1,kernel1,iterations = 1)
cv2.imshow('Dilated',dilate1)

contours, hierarchy = cv2.findContours(dilate1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for xx in contours:
    cv2.drawContours(words_temp,[xx],-1,(255,255,255),-1)
cv2.imshow('Contours from Dilated',words_temp)

contours, hierarchy = cv2.findContours(words_temp,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
    x,y,w,h = cv2.boundingRect(c)
    #cv2.rectangle(prep_img1,(x,y),(x+w,y+h),(255,0,0),1)