Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-16 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found