help with coding Mogrify

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
rleir
Posts: 8
Joined: 2014-09-02T07:22:10-07:00
Authentication code: 6789

help with coding Mogrify

Post by rleir » 2014-09-02T10:30:41-07:00

Here is the command line, which works fine:
$ convert 1345.jpg -colorspace gray \( +clone -blur 0x20 \) -compose Divide_Src -composite 1345photocopy1.jpg

# ref http://www.imagemagick.org/Usage/compose/#divide

I am having trouble coding some PerlMagick to do the same. What I have so far is shakey:

Code: Select all

 
    my $image = Image::Magick->new;
    my $x = $image->read( $sourceFile);
    if ("$x") { print LOGFILE "image read = $x   \n";   }

    $image->Quantize(colorspace=>'gray');
    my $q = $image->Clone();
    $q->Blur( radius=>16);
    $x = $image->Mogrify( 'Composite', compose=>'Divide_Src', composite=>'t' );
    if ("$x") {	print LOGFILE "image modu = $x   \n";   }
This throws an error:

Code: Select all

 Exception 410: composite image required `Image::Magick' @ error/Magick.xs/XS_Image__Magick_Mogrify/8255

User avatar
magick
Site Admin
Posts: 10980
Joined: 2003-05-31T11:32:55-07:00

Re: help with coding Mogrify

Post by magick » 2014-09-03T06:10:12-07:00

Use $image->Composite(), Mogrify is not required. The Composite() method requires an image to composite, use this argument: image=>$q, for example.

rleir
Posts: 8
Joined: 2014-09-02T07:22:10-07:00
Authentication code: 6789

Re: help with coding Mogrify

Post by rleir » 2014-09-03T11:48:47-07:00

Thanks for helping. Now we have this:

Code: Select all

    $image->Quantize(colorspace=>'gray');
    my $q = $image->Clone();
    $q->Blur( radius=>16);
    $x = $image->Composite ( compose=>'Divide_Src', image=>$q );
    if ("$x") {	print LOGFILE "image modu = $x   \n";   }
The resulting image is all white.

There is no mention of compose=>'Divide_Src' in the doco, and I do not see an operator like division:
http://www.imagemagick.org/script/perl- ... manipulate

Evaluate has a divide operator, but it does not seem to work with two images.

snibgo
Posts: 11694
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: help with coding Mogrify

Post by snibgo » 2014-09-03T12:01:03-07:00

The resulting image is all white.
If you divide anything by itself, the result is 1.0, which is white.
snibgo's IM pages: im.snibgo.com

rleir
Posts: 8
Joined: 2014-09-02T07:22:10-07:00
Authentication code: 6789

Re: help with coding Mogrify

Post by rleir » 2014-09-04T06:02:35-07:00

In the original post (above) you will see a convert command line, which works well for me. I would like to translate that to PerlMagick, but no luck yet!

Another post discusses my goals: viewtopic.php?f=22&t=26190
Thanks
Rick

rleir
Posts: 8
Joined: 2014-09-02T07:22:10-07:00
Authentication code: 6789

Re: help with coding Mogrify

Post by rleir » 2014-09-04T12:18:10-07:00

Aha. The Blur parameters.

In the command line, the blur radius of 0x20 is not hexadecimal 20. What it really means is radius=0, sigma=20.

For the same effect, does the perlmagick need to do this?
$q->Blur( radius=>0.0, sigma=>20.0);

Now the results of the Perlmagick are the same as for the command line, and they are suitable for OCR.

Post Reply