September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
6
Task/Hough-transform/Julia/hough-transform.julia
Normal file
6
Task/Hough-transform/Julia/hough-transform.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
using ImageFeatures
|
||||
|
||||
img = fill(false,5,5)
|
||||
img[3,:] .= true
|
||||
|
||||
println(hough_transform_standard(img))
|
||||
38
Task/Hough-transform/Perl-6/hough-transform.pl6
Normal file
38
Task/Hough-transform/Perl-6/hough-transform.pl6
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
39
Task/Hough-transform/Perl/hough-transform.pl
Normal file
39
Task/Hough-transform/Perl/hough-transform.pl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use Imager;
|
||||
|
||||
use constant pi => 3.14159265;
|
||||
|
||||
sub hough {
|
||||
my($im) = shift;
|
||||
my($width) = shift || 460;
|
||||
my($height) = shift || 360;
|
||||
$height = 2 * int $height/2;
|
||||
|
||||
$height = 2 * int $height/2;
|
||||
my($xsize, $ysize) = ($im->getwidth, $im->getheight);
|
||||
my $ht = Imager->new(xsize => $width, ysize => $height);
|
||||
for my $i (0..$height-1) { for my $j (0..$width-1) { $canvas[$i][$j] = 255 } }
|
||||
$ht->box(filled => 1, color => 'white');
|
||||
|
||||
$rmax = sqrt($xsize**2 + $ysize**2);
|
||||
$dr = 2 * $rmax / $height;
|
||||
$dth = pi / $width;
|
||||
|
||||
for $x (0..$xsize-1) {
|
||||
for $y (0..$ysize-1) {
|
||||
my $col = $im->getpixel(x => $x, y => $y);
|
||||
my($r,$g,$b) = $col->rgba;
|
||||
next if $r==255; # && $g==255 && $b==255;
|
||||
for $k (0..$width) {
|
||||
$th = $dth*$k;
|
||||
$r = ($x*cos($th) + $y*sin($th));
|
||||
$iry = ($height/2 + int($r/$dr + 0.5));
|
||||
$ht->setpixel(x => $k, y => $iry, color => [ ($canvas[$iry][$k]--) x 3] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ht;
|
||||
}
|
||||
|
||||
my $img = Imager->new;
|
||||
$img->read(file => 'ref/pentagon.png') or die "Cannot read: ", $img->errstr;
|
||||
$ht->write(file => 'hough_transform.png');
|
||||
53
Task/Hough-transform/Phix/hough-transform.phix
Normal file
53
Task/Hough-transform/Phix/hough-transform.phix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
-- demo\rosetta\Hough_transform.exw
|
||||
include pGUI.e
|
||||
|
||||
function hypot(atom a,b) return sqrt(a*a+b*b) end function
|
||||
|
||||
function hough_transform(imImage im, integer width=460, height=360)
|
||||
height = 2*floor(height / 2)
|
||||
integer xsize = im_width(im),
|
||||
ysize = im_width(im)
|
||||
sequence ht = repeat(repeat(repeat(255,3),width),height)
|
||||
sequence canvas = repeat(repeat(255,width),height)
|
||||
atom rmax = hypot(xsize, ysize),
|
||||
dr = 2*(rmax / height),
|
||||
dth = (PI / width)
|
||||
for y=0 to ysize-1 do
|
||||
for x=0 to xsize-1 do
|
||||
integer {r,g,b} = im_pixel(im, x, y)
|
||||
if r!=255 then
|
||||
for k=1 to width do
|
||||
atom th = dth*(k-1),
|
||||
r2 = (x*cos(th) + y*sin(th))
|
||||
integer iry = (height/2 + floor(r2/dr + 0.5))+1,
|
||||
cik = canvas[iry][k] - 1
|
||||
canvas[iry][k] = cik
|
||||
ht[iry][k] = repeat(cik,3)
|
||||
end for
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
ht = flatten(ht) -- (needed by IupImageRGB)
|
||||
Ihandle new_img = IupImageRGB(width, height, ht)
|
||||
return new_img
|
||||
end function
|
||||
|
||||
IupOpen()
|
||||
|
||||
atom pError = allocate(machine_word())
|
||||
imImage im1 = imFileImageLoadBitmap("Pentagon.png",0,pError)
|
||||
if im1=NULL then ?"error opening Pentagon.png" abort(0) end if
|
||||
Ihandln image1 = IupImageFromImImage(im1),
|
||||
image2 = hough_transform(im1),
|
||||
label1 = IupLabel(),
|
||||
label2 = IupLabel()
|
||||
IupSetAttributeHandle(label1, "IMAGE", image1)
|
||||
IupSetAttributeHandle(label2, "IMAGE", image2)
|
||||
|
||||
Ihandle dlg = IupDialog(IupHbox({label1, label2}))
|
||||
IupSetAttribute(dlg, "TITLE", "Hough transform")
|
||||
IupCloseOnEscape(dlg)
|
||||
IupShow(dlg)
|
||||
|
||||
IupMainLoop()
|
||||
IupClose()
|
||||
Loading…
Add table
Add a link
Reference in a new issue