Page 1 of 1

What diff for grayscale transbetween perlmagic & magic++

Posted: 2006-12-27T04:00:07-07:00
by stanleyweike
Hi,

Recently I found when I was using perlmagick transform a pic to grayscale using
$image->[$i]->Quantize(colorspace=>'gray');
produces different effect from Magick++ by using
mImage.quantizeColorSpace(GRAYColorspace);
mImage.quantizeColors(256);
mImage.quantize();
although I try to change the # of colors, it seems still quite different. I prefer the perl version alg, is there anyone know what is the difference? And what could I do to make it produce the same thing?

thanks a lot

Stan

Posted: 2006-12-27T08:00:21-07:00
by magick
To set the image type to grayscale, try
  • $image->Set(type=>'grayscale');

Posted: 2006-12-27T13:12:05-07:00
by stanleyweike
Thank you for the reply, but what if I want to use C++ to pruduce the effect from perl, how could I do?

thanks

Posted: 2006-12-27T13:43:31-07:00
by magick
With Magick++, use
  • image->type(GrayscaleImageType);
to set transform an image to grayscale.

Posted: 2006-12-27T13:55:37-07:00
by stanleyweike
I have tried

image->type(GrayscaleImageType);
but it is still different from the perl Quantize(colorspace=>'gray');

To me, the perl version is better, is there anyway I could achieve perl effect in C++? By the way, is there any document about Magick++ except the API spec?

Posted: 2006-12-27T14:23:54-07:00
by magick
PerlMagick and Magick++ produce the same grayscale image for us. We're running ImageMagick 6.3.1-4. Our PerlMagick code is:

Code: Select all

use Image::Magick;

$image=Image::Magick->new();
$image->Read('logo.png');
$image->Quantize(colorspace=>'gray');
$image->Write('perl.miff');
Our Magick++ code is:

Code: Select all

#include <Magick++.h>
#include <iostream>
#include <string>

using namespace std;
using namespace Magick;

int main(int argc, char** argv)
{
  try
  {
    Image mImage;
    mImage.read("logo.png");
    mImage.quantizeColorSpace(GRAYColorspace);
    mImage.quantizeColors(256);
    mImage.quantize(); 
    mImage.write("magick++.miff");
  }
  catch (Magick::Exception& err)
  {
    fprintf(stderr, "Exception:%s",err.what());
  }
}
When we run the compare command it returns 0 meaning the images are exactly the same:
  • compare -metric mse perl.miff magick++.miff null:
    0

Posted: 2006-12-27T15:06:54-07:00
by stanleyweike
Hi,

You are right, it is the same! I made a mistake by saving in gif which should be jpg. Sorry for the trouble! And another question is in perl magick there is a method called blackthreshold and whitethreshold, and in magick++ it seems gone, so is there any combination of APIs to achieve the same effect?

thanks

Stan

Posted: 2006-12-27T16:18:24-07:00
by magick
You can always call MagickCore methods directly. For BlackThresholdImage(), use MagickLib::BlackThresholdImage().

Posted: 2006-12-27T18:44:59-07:00
by stanleyweike
For this method BlackThresholdImage(Image *, char * threshold), what is threshold supposed to be, for example in perl I used BlackThresholdImage(threshold=>60000), so what is the corresponding value for threshold here?

thanks

Posted: 2006-12-27T18:54:17-07:00
by magick
Use percentages for thresholding. For all channels, try 20%, for example. You can set individual channels by separating the threshold with commands, for example, 10,20,15%.

Posted: 2006-12-28T15:48:40-07:00
by stanleyweike
Hi, About the BlackThresholdImage function, if I plan to use it in C++, how could I cast a object from Image class to the Image struct in C. Do you have any sample code showing how this function is used?

thanks