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.

In reply to Re: Sobel Operator Edge Detection by dwalton76
in thread Sobel Operator Edge Detection by t-k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.