Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Sobel Operator Edge Detection

by dwalton76 (Initiate)
on Mar 08, 2013 at 21:49 UTC ( [id://1022501]=note: print w/replies, xml ) Need Help??


in reply to Sobel Operator Edge Detection

Thank you for posting this. I was able to speed it up some by storing the RGB pixel values in 2D arrays. The image that I am testing originally took 28 seconds to process and I have it down to 12 seconds. I'll cut-n-paste the parts that I changed:
my $gray = 0; my ( $width, $height ) = $imSrcImg->Get( 'width', 'height' ); my @pixels_red; my @pixels_green; my @pixels_blue; for (my $x = 0; $x < $width; $x++) { for (my $y = 0; $y < $height; $y++) { (my $red, my $green, my $blue) = split(',', $imSrcImg->Get(" +pixel[$x,$y]")); $pixels_red[$x][$y] = $red; $pixels_green[$x][$y] = $green; $pixels_blue[$x][$y] = $blue; } } # Iterate over every pixel in the image and change for my $y ( 1 .. ( $height - 2 ) ) { for my $x ( 1 .. ( $width - 2 ) ) { for ( my $i = -1 ; $i <= 1 ; $i++ ) { for ( my $j = -1 ; $j <= 1 ; $j++ ) { my $r = $pixels_red[$x + $i][$y + $j]; my $g = $pixels_green[$x + $i][$y + $j]; my $b = $pixels_blue[$x + $i][$y + $j]; my $tmp_GX = $GX[ $i + 1 ][ $j + 1 ]; my $tmp_GY = $GY[ $i + 1 ][ $j + 1 ]; if ($tmp_GX) { $sumRx += $r * $tmp_GX; $sumGx += $g * $tmp_GX; $sumBx += $b * $tmp_GX; } if ($tmp_GY) { $sumRy += $r * $tmp_GY; $sumGy += $g * $tmp_GY; $sumBy += $b * $tmp_GY; } } }
The rest of the code is the same.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1022501]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-03-19 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found