<s> import logging <EOL> logging . basicConfig ( level = logging . ERROR ) <EOL> try : <EOL> import cmt . ee_authenticate <EOL> except : <EOL> import sys <EOL> import os . path <EOL> sys . path . append ( os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , '<STR_LIT:..>' ) ) <EOL> import cmt . ee_authenticate <EOL> cmt . ee_authenticate . initialize ( ) <EOL> import time <EOL> import cmt . domain <EOL> from cmt . radar . active_contour import * <EOL> import sys <EOL> import PIL <EOL> from PIL import ImageQt <EOL> import numpy <EOL> from PyQt4 import QtGui , QtCore <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> THIS_FILE_FOLDER = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> domain = cmt . domain . Domain ( os . path . join ( THIS_FILE_FOLDER , '<STR_LIT:..>' ) + '<STR_LIT>' ) <EOL> def active_contour_step ( local_image , snake , step ) : <EOL> '''<STR_LIT>''' <EOL> if snake . done : <EOL> return True <EOL> t = time . time ( ) <EOL> if step % <NUM_LIT:10> == <NUM_LIT:0> : <EOL> snake . respace_nodes ( ) <EOL> snake . shift_nodes ( ) <EOL> snake . fix_geometry ( ) <EOL> else : <EOL> snake . shift_nodes ( ) <EOL> print time . time ( ) - t <EOL> return False <EOL> class ActiveContourWindow ( QtGui . QWidget ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , domain ) : <EOL> super ( ActiveContourWindow , self ) . __init__ ( ) <EOL> self . setGeometry ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . setWindowTitle ( '<STR_LIT>' ) <EOL> self . domain = domain <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> SKYBOX_SCALE = <NUM_LIT> / <NUM_LIT> <EOL> train_domain = domain . training_domain <EOL> try : <EOL> sensor = domain . skybox <EOL> trainSensor = train_domain . skybox <EOL> except : <EOL> sensor = domain . skybox_nir <EOL> trainSensor = train_domain . skybox_nir <EOL> ee_image = sensor . image . toUint16 ( ) <EOL> ee_image_train = trainSensor . image . toUint16 ( ) <EOL> if train_domain . training_features : <EOL> ( band_names , band_statistics ) = compute_band_statistics_features ( ee_image_train , train_domain . training_features ) <EOL> else : <EOL> ( band_names , band_statistics ) = compute_band_statistics ( ee_image_train , train_domain . ground_truth , <EOL> train_domain . bounds ) <EOL> ( self . local_image , self . snake ) = initialize_active_contour ( domain , ee_image , band_statistics , False ) <EOL> channels = [ self . local_image . get_image ( '<STR_LIT>' ) , self . local_image . get_image ( '<STR_LIT>' ) , self . local_image . get_image ( '<STR_LIT>' ) ] <EOL> channel_images = [ PIL . Image . fromarray ( numpy . uint8 ( c / SKYBOX_SCALE ) ) for c in channels ] <EOL> self . display_image = PIL . Image . merge ( '<STR_LIT>' , channel_images ) <EOL> self . step = <NUM_LIT:1> <EOL> self . show ( ) <EOL> def paintEvent ( self , event ) : <EOL> imageqt = ImageQt . ImageQt ( self . display_image ) <EOL> p = QtGui . QPainter ( ) <EOL> p . begin ( self ) <EOL> p . setRenderHint ( QtGui . QPainter . Antialiasing , True ) ; <EOL> scale = self . height ( ) / float ( imageqt . height ( ) + <NUM_LIT:10> ) <EOL> p . scale ( scale , scale ) <EOL> p . translate ( ( self . width ( ) / <NUM_LIT:2> / scale - imageqt . width ( ) / <NUM_LIT:2> ) , <EOL> ( self . height ( ) / <NUM_LIT:2> / scale - imageqt . height ( ) / <NUM_LIT:2> ) ) <EOL> p . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , imageqt . width ( ) , imageqt . height ( ) , QtGui . QColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> p . drawImage ( <NUM_LIT:0> , <NUM_LIT:0> , imageqt ) <EOL> NODE_RADIUS = <NUM_LIT:4> <EOL> for loop in self . snake . loops : <EOL> for i in range ( len ( loop . nodes ) ) : <EOL> p . setPen ( QtGui . QColor ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> p . setBrush ( QtGui . QBrush ( QtGui . QColor ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> p . drawEllipse ( loop . nodes [ i ] [ <NUM_LIT:1> ] - NODE_RADIUS / <NUM_LIT> , <EOL> loop . nodes [ i ] [ <NUM_LIT:0> ] - NODE_RADIUS / <NUM_LIT> , NODE_RADIUS , NODE_RADIUS ) <EOL> for loop in self . snake . loops : <EOL> for i in range ( len ( loop . nodes ) ) : <EOL> if len ( loop . nodes ) > <NUM_LIT:1> : <EOL> n = i + <NUM_LIT:1> <EOL> if n == len ( loop . nodes ) : <EOL> n = <NUM_LIT:0> <EOL> p . setPen ( QtGui . QColor ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> p . drawLine ( loop . nodes [ i ] [ <NUM_LIT:1> ] , loop . nodes [ i ] [ <NUM_LIT:0> ] , loop . nodes [ n ] [ <NUM_LIT:1> ] , loop . nodes [ n ] [ <NUM_LIT:0> ] ) <EOL> p . end ( ) <EOL> def keyPressEvent ( self , event ) : <EOL> '''<STR_LIT>''' <EOL> if event . key ( ) == QtCore . Qt . Key_Space : <EOL> active_contour_step ( self . local_image , self . snake , self . step ) <EOL> self . repaint ( ) <EOL> self . step += <NUM_LIT:1> <EOL> if event . key ( ) == QtCore . Qt . Key_Q : <EOL> QtGui . QApplication . quit ( ) <EOL> ex = ActiveContourWindow ( domain ) <EOL> sys . exit ( app . exec_ ( ) ) </s>
