Example:Hough transform/C: Difference between revisions

Content added Content deleted
(Transfer example from task:Hough transform)
m (Fixed syntax highlighting.)
 
Line 1: Line 1:
=={{Programming-example-page|Hough transform|language=C}}==
==={{Programming-example-page|Hough transform|language=C}}===
{{trans|Tcl}}
{{trans|Tcl}}


(Tested only with the pentagon image given)
(Tested only with the pentagon image given)
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdint.h>
Line 118: Line 118:


return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


Output image (but with white background):
Output image (but with white background):
Line 125: Line 125:
<br style="clear:both" />
<br style="clear:both" />


=== Alternative version ===
===Alternative version===


[[file:penta-hugh.png|thumb]][[file:hugh-lines-in.png|thumb]][[file:hugh-lines-out.png|thumb]]
[[file:penta-hugh.png|thumb]][[file:hugh-lines-in.png|thumb]][[file:hugh-lines-out.png|thumb]]
This code is a little to long to my liking, because I had to put some ad hoc stuff that should be better served by libraries. But you don't want to see libpng code here, trust me.
This code is a little to long to my liking, because I had to put some ad hoc stuff that should be better served by libraries. But you don't want to see libpng code here, trust me.
<lang C>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
Line 380: Line 380:
/* not going to free memory we used: OS can deal with it */
/* not going to free memory we used: OS can deal with it */
return 0;
return 0;
}</lang>
}</syntaxhighlight>
This program takes a pnm file (binary, either P5 or P6) and does the transformation, then dump output onto stdout. Sample images below are output from the pentagram; sample lines with added noise; output of processing that. Both output were with 1.5 gamma.
This program takes a pnm file (binary, either P5 or P6) and does the transformation, then dump output onto stdout. Sample images below are output from the pentagram; sample lines with added noise; output of processing that. Both output were with 1.5 gamma.