Vous êtes sur la page 1sur 2

PRO ImaStat ; -------------------------------------------------------------------------; This procedure loads a true-color image, converts it to grayscale and ; derive a set of statistical parameters

of image ; Input arguments: ; External calls: ; ; ; ; Programmer: Creation Date: Environment: Modifications: None CenterWindowPos M. Messerotti 23.10.2007 IDL 6.4--8.1 08.01.2012 Added Mac OS X sensing

; Version: 0.2 ; -------------------------------------------------------------------------; Set indexed mode for displaying images DEVICE, DECOMPOSED = 0 ; Load grayscale palette LOADCT, 0 ; Identify the Operating System via the relevant system variable op_sys = !VERSION.OS ; Set the proper syntax for file path based on O/S version CASE op_sys OF 'linux' : s_path = !DIR + '/examples/data/'

'darwin' : s_path = !DIR + '/examples/data/' 'Win32' ENDCASE ; Load sample image from IDL directory by converting it to grayscale filename = s_path + 'marsglobe.jpg' READ_JPEG, filename, image, /GRAYSCALE, /TWO_PASS_QUAN ; Derive image size imsize = SIZE(image) x_size = imsize[1] y_size = imsize[2] ; Derive centered position for graphic window CenterWindowPos, 2 * x_size, y_size, x_wpos, y_wpos ; Open graphic window with doubled x-size to display two quadrants WINDOW, 1, XSIZE = 2 * x_size, YSIZE = y_size, XPOS = x_wpos, YPOS = y_wpos, $ TITLE = 'Grayscale Image and Statistics' ; Display original image in left quadrant TV, image, 0 ; Derive image statistics IMAGE_STATISTICS, image, COUNT DATA_SUM MINIMUM MAXIMUM MEAN STDDEV = = = = = = TotalPixelNumber, PixelValueSum, PixelMin, PixelMax, PixelMean, PixelSTDev, $ $ $ $ $ $ $ : s_path = !DIR + '\examples\data\'

"!

SUM_OF_SQUARES = PixelSquareSum, VARIANCE = PixelVariance ; Write statistics in right quadrant y_pos_step = 0.1

XYOUTS, 0.550, 1.0 - 0.5 * y_pos_step, 'IMAGE STATISTICS', /NORM XYOUTS, 0.550, 1.0 - 1.5 * y_pos_step, 'Size X x Y [pxs] STRTRIM(STRING(y_size), 2) , /NORM XYOUTS, 0.550, 1.0 - 2.5 * y_pos_step, 'Total pixel number /NORM = ' + STRTRIM(STRING(x_size), 2) + ' x ' +

= ' + STRTRIM(STRING(TotalPixelNumber), 2), 2), 2), 2), 2), 2), 2), 2),

XYOUTS, 0.550, 1.0 - 3.5 * y_pos_step, 'Sum of pixel values = ' + STRTRIM(STRING(PixelValueSum), /NORM XYOUTS, 0.550, 1.0 - 4.5 * y_pos_step, 'Min /NORM XYOUTS, 0.550, 1.0 - 5.5 * y_pos_step, 'Max /NORM pixel value = ' pixel value = ' + STRTRIM(STRING(PixelMin), + STRTRIM(STRING(PixelMax), + STRTRIM(STRING(PixelMean),

XYOUTS, 0.550, 1.0 - 6.5 * y_pos_step, 'Mean pixel value = ' /NORM

XYOUTS, 0.550, 1.0 - 7.5 * y_pos_step, 'Pixel STD deviation = ' + STRTRIM(STRING(PixelSTDev), /NORM XYOUTS, 0.550, 1.0 - 8.5 * y_pos_step, 'Pixel square sum = ' /NORM XYOUTS, 0.550, 1.0 - 9.5 * y_pos_step, 'Pixel variance = ' /NORM ; Wait for left mouse button release PRINT, "Press and release left mouse button to quit' CURSOR, xcpos, ycpos, 4 ; Delete window WDELETE ; End of procedure END + STRTRIM(STRING(PixelSquareSum), + STRTRIM(STRING(PixelVariance),

#!

Vous aimerez peut-être aussi