***************************************************************************** * Project: ACTIVE VISION * Module: CLS_HSV - Color Space Classifier * Version: 2.0 * Date: 07/20/98 * Company: University of California, Santa Barbara * Author: Daryl Fortney * References: MDC40IC: Spectrum Signal Processing * RGB -> HSV Conversion: Keith Jack, Video Demystified - * A Handbook for the Digital Engineer, Brooktree, 1993. * * Function: * void _ClassifyHSV(X_S,Y_S,X_E,Y_E) * INPUTS: * H_LUT Hue 256 Boolean LUT * S_LO Saturation Floating Point Cutoff * V_LO Value Floating Point Cutoff * OVR Overlay Classification Result Flag * X_RES X Sample Resolution * Y_RES Y Sample Resolution * WSH Washout Flag * OUTPUTS: * H_LUT Hue Histogram * X_M X Mean * Y_M Y Mean * NUM Number of Classified Pixels * * This function classifies and computes the OUTPUT histograms * X,Y statistics of the defined region of the IMAGE screen for the MDC40IC * card produced by Spectrum Signal Processing. Classification thresholds * on the INPUT histogram H and the scalars (long)V_THR & (float)S_THR. * MSK is used for Color Space Masking. OVR is used to seed the OVERLAY * memory. X_RES and Y_RES are the corresponding sample resolutions. * WSH is a flag used to signify possible classifier washout exceptions. * On return, X_M and Y_M contain the classification description. * NUM is number of non-washed out positively classified points. * H_LUT is a histogram of the positively classified pixels Hue. ***************************************************************************** .version 40 * ROUTINES .global _ClassifyHSV * GLOBAL INPUTS _H_LUT .usect "clsdat",256 ; Hue Histogram .global _H_LUT ; . _S_LO .usect "clsdat",1 ; Saturation Threshold LO .global _S_LO ; . _V_LO .usect "clsdat",1 ; Value Threshold LO .global _V_LO ; . _OVR .usect "clsdat",1 ; OVERLAY VALUE .global _OVR ; . _X_RES .usect "clsdat",1 ; X_RESOLUTION .global _X_RES ; . _Y_RES .usect "clsdat",1 ; Y_RESOLUTION .global _Y_RES ; . _WSH .usect "clsdat",1 ; WASHOUT FLAG .global _WSH ; . * GLOBAL OUTPUTS _NUM .usect "clsdat",1 ; Number of Pixels .global _NUM ; . _X_M .usect "clsdat",1 ; X Mean .global _X_M ; . _Y_M .usect "clsdat",1 ; Y Mean .global _Y_M ; . * EXTERNAL REGISTERS R .usect "clsdat",1 ; . G .usect "clsdat",1 ; . B .usect "clsdat",1 ; . .text * LOCAL POINTERS I_P .word 010000000h ; IMAGE Buffer Pointer .asg ar0,I_ar ; . H_P .word _H_LUT ; HUE Histogram Pointer .asg ar1,H_ar ; . * INTERNAL REGISTERS .asg *-ar3(2),X_S ; Work Region Left Coordinate .asg *-ar3(3),Y_S ; Work Region Top Coordinate .asg *-ar3(4),X_E ; Work Region Right Coordinate .asg *-ar3(5),Y_E ; Work Region Bottom Coordinate .asg r0,V1 ; Transformation Variable .asg r1,V2 ; Transformation Variable .asg r2,V3 ; Transformation Variable .asg r3,V4 ; Transformation Variable .asg r4,C ; Hue Sector Offset .asg r5,X ; X Position .asg r6,Y ; Y Position .asg r7,X_SUM ; Classified X Position Sum .asg r8,Y_SUM ; Classified Y Position Sum .asg r9,NUM ; Classified Number of Pixels .asg r10,W_NUM ; Washed Out Number of Pixels * Classifier Routine Begins Here _ClassifyHSV: push ar3 ldi sp,ar3 push r4 push r5 push r6 pushf r6 push r7 pushf r7 push r8 push ar4 ; * Setup IO Pointers * lda @H_P,H_ar ; H_ar = Pointer to H_HST I ; * Setup Statistical Variables * ldi 0,X_SUM ; X_SUM = 0 ldi 0,Y_SUM ; Y_SUM = 0 ldf 0.0,NUM ; NUM = 0.0 ldf 0.0,W_NUM ; W_NUM = 0.0 ; * Setup Initial Loop Vars * ldi X_S,X ; X = X_START ldi Y_S,Y ; Y = Y_START ldi Y_S,I_ar ; I_ar = 512*Y_S+X_S+I_P mpyi 512,I_ar ; . addi X_S,I_ar ; . addi @I_P,I_ar ; . .align * For Each Pixel in Y Direction yloop: ; do{ lbu0 *I_ar,V1 ; Extract R (0x000F) -> V1 lbu1 *I_ar,V2 ; Extract G (0x00F0) -> V2 lbu2 *I_ar,V3 ; Extract B (0x0F00) -> V3 * For Each Pixel in X Direction * 1. Find & Threshold Value = Max(R,G,B) * 2. Find & Threshold Saturation = 1/(max-min) * 3. Find & Threshold Hue xloop: ; do{ sti V1,@R ; Assume Red Max sti V2,@G ; . sti V3,@B ; . ldf 42.66668,C ; . cmpi @G,V1 ; Check For Green Max ldilo @G,V1 ; . ldilo @B,V2 ; . ldilo @R,V3 ; . ldflo 128.0,C ; . cmpi @B,V1 ; Check For Blue Max ldilo @B,V1 ; . ldilo @R,V2 ; . ldilo @G,V3 ; . ldflo 213.33332,C ; . * Compute and Threshold on Value value: * sti 0,@_OVR cmpi @_V_LO,V1 ; V1 = Value = Max bnd xloop_end ; . * bnd overlay float V1 ;D V1 = (float) Max float V2 ;D V2 = (float) Order 1 float V3 ;D V3 = (float) Order 2 * Compute and Threshold on Saturation saturation: subf V3,V2,V4 ; V4 = Hue Sector = Order 1 - Order 2 ldfn V2,V3 ; V3 = (float) 1/(Max-Min) subf V3,V1,V3 ; . rcpf V3 ; . mpyf V3,V1,V2 ; V2 = Saturation = V1 * V3 cmpf @_S_LO,V2 ; . bn hue ; . * sti 0,@_OVR ldi @_WSH,V2 ; * Check Washout Condition * bz xloop_end ; . * bz overlay addf 1.0,W_NUM ; . b classify ; . * Compute and Threshold on Hue hue: mpyf 42.66667,V3 ;D H = C+42.66667*V4*V3 mpyf V4,V3 ;D . addf C,V3 ;D . fix V3,ir0 ; . * sti 0,@_OVR ldi *+H_ar(ir0),V2 ; . bz xloop_end ; * bz overlay * Update Statistics With Newly Classified Pixel classify: addi 1,V2 ; Update Hue Histogram sti V2,*+H_ar(ir0) ; . addf 1.0,NUM ; Update NUM addi X,X_SUM ; Update X_SUM addi Y,Y_SUM ; Update Y_SUM * sti 3,@_OVR * Optional Overlay Of Results overlay: ldi @_OVR,V1 lda @I_P,ir0 sti V1,*+I_ar(ir0) * Next Pixel xloop_end: addi @_X_RES,I_ar ; I_ar++ addi @_X_RES,X ; X++ cmpi X_E,X ; . bnd xloop ; }while (X < X_E) lbu0 *I_ar,V1 ;D Extract R (0x000F) -> V1 lbu1 *I_ar,V2 ;D Extract G (0x00F0) -> V2 lbu2 *I_ar,V3 ;D Extract B (0x0F00) -> V3 ldi X_S,X ; Y++ addi @_Y_RES,Y ; . ldi Y,I_ar ; . cmpi Y_E,Y ; } while (Y