From ecea3f1e323fd8004460fe11f4a99a99916a54f3 Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Tue, 19 Mar 2013 16:42:31 +0000 Subject: add a 08_GPU_morphology example svn path=/trunk/externals/pix_opencv/; revision=17065 --- examples/08_GPU_morphology/erode.frag | 120 ++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 examples/08_GPU_morphology/erode.frag (limited to 'examples/08_GPU_morphology/erode.frag') diff --git a/examples/08_GPU_morphology/erode.frag b/examples/08_GPU_morphology/erode.frag new file mode 100644 index 0000000..90ed15a --- /dev/null +++ b/examples/08_GPU_morphology/erode.frag @@ -0,0 +1,120 @@ +// up to 7x7 erode algorithm +// Antoine Villeret - 2012 + +#extension GL_ARB_texture_rectangle : enable + +uniform sampler2DRect frame; +uniform int size; +uniform int pattern; // 0 cross, 1 square + +vec2 texcoord0 = gl_TexCoord[0].st; + +vec2 texcoord00 = texcoord0 + vec2(-3, -3); +vec2 texcoord01 = texcoord0 + vec2(-2, -3); +vec2 texcoord02 = texcoord0 + vec2(-1, -3); +vec2 texcoord03 = texcoord0 + vec2(0, -3); +vec2 texcoord04 = texcoord0 + vec2(1, -3); +vec2 texcoord05 = texcoord0 + vec2(2, -3); +vec2 texcoord06 = texcoord0 + vec2(3, -3); + +vec2 texcoord10 = texcoord0 + vec2(-3, -2); +vec2 texcoord11 = texcoord0 + vec2(-2, -2); +vec2 texcoord12 = texcoord0 + vec2(-1, -2); +vec2 texcoord13 = texcoord0 + vec2(0, -2); +vec2 texcoord14 = texcoord0 + vec2(1, -2); +vec2 texcoord15 = texcoord0 + vec2(2, -2); +vec2 texcoord16 = texcoord0 + vec2(3, -2); + +vec2 texcoord20 = texcoord0 + vec2(-3, -1); +vec2 texcoord21 = texcoord0 + vec2(-2, -1); +vec2 texcoord22 = texcoord0 + vec2(-1, -1); +vec2 texcoord23 = texcoord0 + vec2(0, -1); +vec2 texcoord24 = texcoord0 + vec2(1, -1); +vec2 texcoord25 = texcoord0 + vec2(2, -1); +vec2 texcoord26 = texcoord0 + vec2(3, -1); + +vec2 texcoord30 = texcoord0 + vec2(-3, 0); +vec2 texcoord31 = texcoord0 + vec2(-2, 0); +vec2 texcoord32 = texcoord0 + vec2(-1, 0); +vec2 texcoord33 = texcoord0 + vec2(0, 0); // center pixel == texcoord0 +vec2 texcoord34 = texcoord0 + vec2(1, 0); +vec2 texcoord35 = texcoord0 + vec2(2, 0); +vec2 texcoord36 = texcoord0 + vec2(3, 0); + +vec2 texcoord40 = texcoord0 + vec2(-3, 1); +vec2 texcoord41 = texcoord0 + vec2(-2, 1); +vec2 texcoord42 = texcoord0 + vec2(-1, 1); +vec2 texcoord43 = texcoord0 + vec2(0, 1); +vec2 texcoord44 = texcoord0 + vec2(1, 1); +vec2 texcoord45 = texcoord0 + vec2(2, 1); +vec2 texcoord46 = texcoord0 + vec2(3, 1); + +vec2 texcoord50 = texcoord0 + vec2(-3, 2); +vec2 texcoord51 = texcoord0 + vec2(-2, 2); +vec2 texcoord52 = texcoord0 + vec2(-1, 2); +vec2 texcoord53 = texcoord0 + vec2(0, 2); +vec2 texcoord54 = texcoord0 + vec2(1, 2); +vec2 texcoord55 = texcoord0 + vec2(2, 2); +vec2 texcoord56 = texcoord0 + vec2(3, 2); + +vec2 texcoord60 = texcoord0 + vec2(-3, 3); +vec2 texcoord61 = texcoord0 + vec2(-2, 3); +vec2 texcoord62 = texcoord0 + vec2(-1, 3); +vec2 texcoord63 = texcoord0 + vec2(0, 3); +vec2 texcoord64 = texcoord0 + vec2(1, 3); +vec2 texcoord65 = texcoord0 + vec2(2, 3); +vec2 texcoord66 = texcoord0 + vec2(3, 3); + + +void main (void) +{ + float closed = texture2DRect(frame, texcoord33).r; // assume gray image + + // 1 pixel cross + closed = min(closed, texture2DRect(frame, texcoord34).r); + closed = min(closed, texture2DRect(frame, texcoord32).r); + closed = min(closed, texture2DRect(frame, texcoord23).r); + closed = min(closed, texture2DRect(frame, texcoord43).r); + + if ( pattern == 1 ) { + // 1 pixel diag + closed = min(closed, texture2DRect(frame, texcoord22).r); + closed = min(closed, texture2DRect(frame, texcoord44).r); + closed = min(closed, texture2DRect(frame, texcoord24).r); + closed = min(closed, texture2DRect(frame, texcoord42).r); + } + + if ( size >= 2 ) { + // 2 pixels cross + closed = min(closed, texture2DRect(frame, texcoord35).r); + closed = min(closed, texture2DRect(frame, texcoord31).r); + closed = min(closed, texture2DRect(frame, texcoord13).r); + closed = min(closed, texture2DRect(frame, texcoord53).r); + + if ( pattern == 1 ) { + // 2 pixel diag + closed = min(closed, texture2DRect(frame, texcoord11).r); + closed = min(closed, texture2DRect(frame, texcoord55).r); + closed = min(closed, texture2DRect(frame, texcoord15).r); + closed = min(closed, texture2DRect(frame, texcoord51).r); + } + } + + if ( size == 3 ) { + // 3 pixels cross + closed = min(closed, texture2DRect(frame, texcoord36).r); + closed = min(closed, texture2DRect(frame, texcoord30).r); + closed = min(closed, texture2DRect(frame, texcoord03).r); + closed = min(closed, texture2DRect(frame, texcoord63).r); + + if ( pattern == 1 ) { + // 3 pixel diag + closed = min(closed, texture2DRect(frame, texcoord00).r); + closed = min(closed, texture2DRect(frame, texcoord66).r); + closed = min(closed, texture2DRect(frame, texcoord06).r); + closed = min(closed, texture2DRect(frame, texcoord60).r); + } + } + + gl_FragColor = vec4(vec3(closed),1); +} -- cgit v1.2.1