Hough transform: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) m →{{header|Perl}}: corrected read of existing image |
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
||
Line 479:
<pre>java HoughTransform pentagon.png JavaHoughTransform.png 640 480 100</pre>
<br style="clear:both" />
=={{header|Julia}}==
Line 641 ⟶ 640:
* see [[Example:Hough transform/MATLAB]]
=={{header|Perl}}==
Line 685 ⟶ 683:
$ht->write(file => 'hough_transform.png');
</lang>
=={{header|Perl 6}}==▼
The <code>GD</code> module the output palette to 255 colors, so only transform darker pixels in the image.▼
{{trans|Perl}}▼
<lang perl6>use GD;▼
my $filename = 'pentagon.ppm';▼
my $in = open($filename, :r, :enc<iso-8859-1>);▼
my ($type, $dim, $depth) = $in.lines[^3];▼
my ($xsize,$ysize) = split ' ', $dim;▼
my ($width, $height) = 460, 360;▼
my $image = GD::Image.new($width, $height);▼
my @canvas = [255 xx $width] xx $height;▼
my $rmax = sqrt($xsize**2 + $ysize**2);▼
my $dr = 2 * $rmax / $height;▼
my $dth = π / $width;▼
my $pixel = 0;▼
my %cstore;▼
for $in.lines.ords -> $r, $g, $b {▼
$pixel++;▼
next if $r > 130;▼
my $x = $pixel % $xsize;▼
my $y = floor $pixel / $xsize;▼
(0..^$width).race.map: -> $k {▼
my $th = $dth*$k;▼
my $r = ($x*cos($th) + $y*sin($th));▼
my $iry = ($height/2 + ($r/$dr).round(1)).Int;▼
my $c = '#' ~ (@canvas[$iry][$k]--).base(16) x 3;▼
%cstore{$c} = $image.colorAllocate($c) if %cstore{$c}:!exists;▼
$image.pixel($k, $iry, %cstore{$c});▼
}▼
}▼
my $png_fh = $image.open("hough-transform.png", "wb");▼
$image.output($png_fh, GD_PNG);▼
$png_fh.close;</lang>▼
See [https://github.com/thundergnat/rc/blob/master/img/hough-transform.png Hough Transform] (offsite .png image)▼
=={{header|Phix}}==
Line 833 ⟶ 788:
=={{header|Racket}}==
* see [[Example:Hough transform/Racket]]
(formerly Perl 6)
▲The <code>GD</code> module the output palette to 255 colors, so only transform darker pixels in the image.
▲{{trans|Perl}}
▲<lang perl6>use GD;
▲my $filename = 'pentagon.ppm';
▲my $in = open($filename, :r, :enc<iso-8859-1>);
▲my ($type, $dim, $depth) = $in.lines[^3];
▲my ($xsize,$ysize) = split ' ', $dim;
▲my ($width, $height) = 460, 360;
▲my $image = GD::Image.new($width, $height);
▲my @canvas = [255 xx $width] xx $height;
▲my $rmax = sqrt($xsize**2 + $ysize**2);
▲my $dr = 2 * $rmax / $height;
▲my $dth = π / $width;
▲my $pixel = 0;
▲my %cstore;
▲for $in.lines.ords -> $r, $g, $b {
▲ $pixel++;
▲ next if $r > 130;
▲ my $x = $pixel % $xsize;
▲ my $y = floor $pixel / $xsize;
▲ (0..^$width).race.map: -> $k {
▲ my $th = $dth*$k;
▲ my $r = ($x*cos($th) + $y*sin($th));
▲ my $iry = ($height/2 + ($r/$dr).round(1)).Int;
▲ my $c = '#' ~ (@canvas[$iry][$k]--).base(16) x 3;
▲ %cstore{$c} = $image.colorAllocate($c) if %cstore{$c}:!exists;
▲ $image.pixel($k, $iry, %cstore{$c});
▲ }
▲}
▲my $png_fh = $image.open("hough-transform.png", "wb");
▲$image.output($png_fh, GD_PNG);
▲$png_fh.close;</lang>
▲See [https://github.com/thundergnat/rc/blob/master/img/hough-transform.png Hough Transform] (offsite .png image)
=={{header|Ruby}}==
|