mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-07-25 02:39:55 +02:00
move all plotting code to EynollahPlotter
This commit is contained in:
parent
853fd12e40
commit
c2e9ebb366
5 changed files with 219 additions and 266 deletions
|
@ -372,108 +372,9 @@ def boosting_headers_by_longshot_region_segmentation(textregion_pre_p, textregio
|
|||
|
||||
|
||||
def find_num_col_deskew(regions_without_seperators, sigma_, multiplier=3.8):
|
||||
regions_without_seperators_0=regions_without_seperators[:,:].sum(axis=1)
|
||||
|
||||
##meda_n_updown=regions_without_seperators_0[len(regions_without_seperators_0)::-1]
|
||||
|
||||
##first_nonzero=(next((i for i, x in enumerate(regions_without_seperators_0) if x), 0))
|
||||
##last_nonzero=(next((i for i, x in enumerate(meda_n_updown) if x), 0))
|
||||
|
||||
##last_nonzero=len(regions_without_seperators_0)-last_nonzero
|
||||
|
||||
|
||||
y=regions_without_seperators_0#[first_nonzero:last_nonzero]
|
||||
|
||||
##y_help=np.zeros(len(y)+20)
|
||||
|
||||
##y_help[10:len(y)+10]=y
|
||||
|
||||
##x=np.array( range(len(y)) )
|
||||
|
||||
|
||||
|
||||
|
||||
##zneg_rev=-y_help+np.max(y_help)
|
||||
|
||||
##zneg=np.zeros(len(zneg_rev)+20)
|
||||
|
||||
##zneg[10:len(zneg_rev)+10]=zneg_rev
|
||||
|
||||
z=gaussian_filter1d(y, sigma_)
|
||||
###zneg= gaussian_filter1d(zneg, sigma_)
|
||||
|
||||
|
||||
###peaks_neg, _ = find_peaks(zneg, height=0)
|
||||
###peaks, _ = find_peaks(z, height=0)
|
||||
|
||||
###peaks_neg=peaks_neg-10-10
|
||||
|
||||
####print(np.std(z),'np.std(z)np.std(z)np.std(z)')
|
||||
|
||||
#####plt.plot(z)
|
||||
#####plt.show()
|
||||
|
||||
#####plt.imshow(regions_without_seperators)
|
||||
#####plt.show()
|
||||
###"""
|
||||
###last_nonzero=last_nonzero-0#100
|
||||
###first_nonzero=first_nonzero+0#+100
|
||||
|
||||
###peaks_neg=peaks_neg[(peaks_neg>first_nonzero) & (peaks_neg<last_nonzero)]
|
||||
|
||||
###peaks=peaks[(peaks>.06*regions_without_seperators.shape[1]) & (peaks<0.94*regions_without_seperators.shape[1])]
|
||||
###"""
|
||||
###interest_pos=z[peaks]
|
||||
|
||||
###interest_pos=interest_pos[interest_pos>10]
|
||||
|
||||
###interest_neg=z[peaks_neg]
|
||||
|
||||
###min_peaks_pos=np.mean(interest_pos)
|
||||
###min_peaks_neg=0#np.min(interest_neg)
|
||||
|
||||
###dis_talaei=(min_peaks_pos-min_peaks_neg)/multiplier
|
||||
####print(interest_pos)
|
||||
###grenze=min_peaks_pos-dis_talaei#np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0
|
||||
|
||||
###interest_neg_fin=interest_neg[(interest_neg<grenze)]
|
||||
###peaks_neg_fin=peaks_neg[(interest_neg<grenze)]
|
||||
###interest_neg_fin=interest_neg[(interest_neg<grenze)]
|
||||
|
||||
###"""
|
||||
###if interest_neg[0]<0.1:
|
||||
###interest_neg=interest_neg[1:]
|
||||
###if interest_neg[len(interest_neg)-1]<0.1:
|
||||
###interest_neg=interest_neg[:len(interest_neg)-1]
|
||||
|
||||
|
||||
|
||||
###min_peaks_pos=np.min(interest_pos)
|
||||
###min_peaks_neg=0#np.min(interest_neg)
|
||||
|
||||
|
||||
###dis_talaei=(min_peaks_pos-min_peaks_neg)/multiplier
|
||||
###grenze=min_peaks_pos-dis_talaei#np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0
|
||||
###"""
|
||||
####interest_neg_fin=interest_neg#[(interest_neg<grenze)]
|
||||
####peaks_neg_fin=peaks_neg#[(interest_neg<grenze)]
|
||||
####interest_neg_fin=interest_neg#[(interest_neg<grenze)]
|
||||
|
||||
###num_col=(len(interest_neg_fin))+1
|
||||
|
||||
|
||||
###p_l=0
|
||||
###p_u=len(y)-1
|
||||
###p_m=int(len(y)/2.)
|
||||
###p_g_l=int(len(y)/3.)
|
||||
###p_g_u=len(y)-int(len(y)/3.)
|
||||
|
||||
|
||||
###diff_peaks=np.abs( np.diff(peaks_neg_fin) )
|
||||
###diff_peaks_annormal=diff_peaks[diff_peaks<30]
|
||||
|
||||
#print(len(interest_neg_fin),np.mean(interest_neg_fin))
|
||||
return np.std(z)#interest_neg_fin,np.std(z)
|
||||
regions_without_seperators_0 = regions_without_seperators[:,:].sum(axis=1)
|
||||
z = gaussian_filter1d(regions_without_seperators_0, sigma_)
|
||||
return np.std(z)
|
||||
|
||||
def return_hor_spliter_by_index_for_without_verticals(peaks_neg_fin_t, x_min_hor_some, x_max_hor_some):
|
||||
# print(peaks_neg_fin_t,x_min_hor_some,x_max_hor_some)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import cv2
|
||||
from scipy.signal import find_peaks
|
||||
|
@ -1485,7 +1484,7 @@ def textline_contours_postprocessing(textline_mask, slope, contour_text_interest
|
|||
|
||||
return contours_rotated_clean
|
||||
|
||||
def seperate_lines_new2(img_path, thetha, num_col, slope_region, dir_of_all, image_filename_stem):
|
||||
def seperate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
||||
|
||||
if num_col == 1:
|
||||
num_patches = int(img_path.shape[1] / 200.0)
|
||||
|
@ -1536,7 +1535,7 @@ def seperate_lines_new2(img_path, thetha, num_col, slope_region, dir_of_all, ima
|
|||
|
||||
sigma = 2
|
||||
try:
|
||||
slope_xline = return_deskew_slop(img_xline, sigma, dir_of_all=dir_of_all, image_filename_stem=image_filename_stem)
|
||||
slope_xline = return_deskew_slop(img_xline, sigma, plotter=plotter)
|
||||
except:
|
||||
slope_xline = 0
|
||||
|
||||
|
@ -1593,29 +1592,10 @@ def seperate_lines_new2(img_path, thetha, num_col, slope_region, dir_of_all, ima
|
|||
# plt.show()
|
||||
return img_patch_ineterst_revised
|
||||
|
||||
def return_deskew_slop(img_patch_org, sigma_des, main_page=False, dir_of_all=None, image_filename_stem=None):
|
||||
def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
||||
|
||||
|
||||
if main_page and dir_of_all is not None:
|
||||
|
||||
|
||||
plt.figure(figsize=(80,40))
|
||||
plt.rcParams['font.size']='50'
|
||||
plt.subplot(1,2,1)
|
||||
plt.imshow(img_patch_org)
|
||||
plt.subplot(1,2,2)
|
||||
plt.plot(gaussian_filter1d(img_patch_org.sum(axis=1), 3),np.array(range(len(gaussian_filter1d(img_patch_org.sum(axis=1), 3)))),linewidth=8)
|
||||
plt.xlabel('Density of textline prediction in direction of X axis',fontsize=60)
|
||||
plt.ylabel('Height',fontsize=60)
|
||||
plt.yticks([0,len(gaussian_filter1d(img_patch_org.sum(axis=1), 3))])
|
||||
plt.gca().invert_yaxis()
|
||||
|
||||
plt.savefig(os.path.join(dir_of_all, image_filename_stem+'_density_of_textline.png'))
|
||||
#print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar')
|
||||
|
||||
#img_patch_org=resize_image(img_patch_org,int(img_patch_org.shape[0]*2.5),int(img_patch_org.shape[1]/2.5))
|
||||
|
||||
#print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar2')
|
||||
if main_page and plotter:
|
||||
plotter.save_plot_of_textline_density(img_patch_org)
|
||||
|
||||
img_int=np.zeros((img_patch_org.shape[0],img_patch_org.shape[1]))
|
||||
img_int[:,:]=img_patch_org[:,:]#img_patch_org[:,:,0]
|
||||
|
@ -1713,17 +1693,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, dir_of_all=Non
|
|||
var_res.append(var_spectrum)
|
||||
|
||||
|
||||
if dir_of_all is not None:
|
||||
#print('galdi?')
|
||||
plt.figure(figsize=(60,30))
|
||||
plt.rcParams['font.size']='50'
|
||||
plt.plot(angels,np.array(var_res),'-o',markersize=25,linewidth=4)
|
||||
plt.xlabel('angle',fontsize=50)
|
||||
plt.ylabel('variance of sum of rotated textline in direction of x axis',fontsize=50)
|
||||
|
||||
plt.plot(angels[np.argmax(var_res)],var_res[np.argmax(np.array(var_res))] ,'*',markersize=50,label='Angle of deskewing=' +str("{:.2f}".format(angels[np.argmax(var_res)]))+r'$\degree$')
|
||||
plt.legend(loc='best')
|
||||
plt.savefig(os.path.join(dir_of_all,image_filename_stem+'_rotation_angle.png'))
|
||||
if plotter:
|
||||
plotter.save_plot_of_rotation_angle(angels, var_res)
|
||||
try:
|
||||
var_res=np.array(var_res)
|
||||
ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue