What diff for grayscale transbetween perlmagic & magic++

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stanleyweike

What diff for grayscale transbetween perlmagic & magic++

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

To set the image type to grayscale, try
  • $image->Set(type=>'grayscale');
stanleyweike

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

With Magick++, use
  • image->type(GrayscaleImageType);
to set transform an image to grayscale.
stanleyweike

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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
stanleyweike

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

You can always call MagickCore methods directly. For BlackThresholdImage(), use MagickLib::BlackThresholdImage().
stanleyweike

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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%.
stanleyweike

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests