<s> '''<STR_LIT>''' <EOL> import cv2 <EOL> import numpy as np <EOL> bins = np . arange ( <NUM_LIT> ) . reshape ( <NUM_LIT> , <NUM_LIT:1> ) <EOL> def hist_curve ( im ) : <EOL> h = np . zeros ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) <EOL> if len ( im . shape ) == <NUM_LIT:2> : <EOL> color = [ ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) ] <EOL> elif im . shape [ <NUM_LIT:2> ] == <NUM_LIT:3> : <EOL> color = [ ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) ] <EOL> for ch , col in enumerate ( color ) : <EOL> hist_item = cv2 . calcHist ( [ im ] , [ ch ] , None , [ <NUM_LIT> ] , [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> cv2 . normalize ( hist_item , hist_item , <NUM_LIT:0> , <NUM_LIT:255> , cv2 . NORM_MINMAX ) <EOL> hist = np . int32 ( np . around ( hist_item ) ) <EOL> pts = np . int32 ( np . column_stack ( ( bins , hist ) ) ) <EOL> cv2 . polylines ( h , [ pts ] , False , col ) <EOL> y = np . flipud ( h ) <EOL> return y <EOL> def hist_lines ( im ) : <EOL> h = np . zeros ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) <EOL> if len ( im . shape ) != <NUM_LIT:2> : <EOL> print "<STR_LIT>" <EOL> im = cv2 . cvtColor ( im , cv2 . COLOR_BGR2GRAY ) <EOL> hist_item = cv2 . calcHist ( [ im ] , [ <NUM_LIT:0> ] , None , [ <NUM_LIT> ] , [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> cv2 . normalize ( hist_item , hist_item , <NUM_LIT:0> , <NUM_LIT:255> , cv2 . NORM_MINMAX ) <EOL> hist = np . int32 ( np . around ( hist_item ) ) <EOL> for x , y in enumerate ( hist ) : <EOL> cv2 . line ( h , ( x , <NUM_LIT:0> ) , ( x , y ) , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) ) <EOL> y = np . flipud ( h ) <EOL> return y <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> im = cv2 . imread ( sys . argv [ <NUM_LIT:1> ] ) <EOL> else : <EOL> im = cv2 . imread ( '<STR_LIT>' ) <EOL> print "<STR_LIT>" <EOL> gray = cv2 . cvtColor ( im , cv2 . COLOR_BGR2GRAY ) <EOL> print '''<STR_LIT>''' <EOL> cv2 . imshow ( '<STR_LIT:image>' , im ) <EOL> while True : <EOL> k = cv2 . waitKey ( <NUM_LIT:0> ) & <NUM_LIT> <EOL> if k == ord ( '<STR_LIT:a>' ) : <EOL> curve = hist_curve ( im ) <EOL> cv2 . imshow ( '<STR_LIT>' , curve ) <EOL> cv2 . imshow ( '<STR_LIT:image>' , im ) <EOL> print '<STR_LIT:a>' <EOL> elif k == ord ( '<STR_LIT:b>' ) : <EOL> print '<STR_LIT:b>' <EOL> lines = hist_lines ( im ) <EOL> cv2 . imshow ( '<STR_LIT>' , lines ) <EOL> cv2 . imshow ( '<STR_LIT:image>' , gray ) <EOL> elif k == ord ( '<STR_LIT:c>' ) : <EOL> print '<STR_LIT:c>' <EOL> equ = cv2 . equalizeHist ( gray ) <EOL> lines = hist_lines ( equ ) <EOL> cv2 . imshow ( '<STR_LIT>' , lines ) <EOL> cv2 . imshow ( '<STR_LIT:image>' , equ ) <EOL> elif k == ord ( '<STR_LIT:d>' ) : <EOL> print '<STR_LIT:d>' <EOL> curve = hist_curve ( gray ) <EOL> cv2 . imshow ( '<STR_LIT>' , curve ) <EOL> cv2 . imshow ( '<STR_LIT:image>' , gray ) <EOL> elif k == ord ( '<STR_LIT:e>' ) : <EOL> print '<STR_LIT:e>' <EOL> norm = cv2 . normalize ( gray , alpha = <NUM_LIT:0> , beta = <NUM_LIT:255> , norm_type = cv2 . NORM_MINMAX ) <EOL> lines = hist_lines ( norm ) <EOL> cv2 . imshow ( '<STR_LIT>' , lines ) <EOL> cv2 . imshow ( '<STR_LIT:image>' , norm ) <EOL> elif k == <NUM_LIT> : <EOL> print '<STR_LIT>' <EOL> cv2 . destroyAllWindows ( ) <EOL> break <EOL> cv2 . destroyAllWindows ( ) </s>
