Page 1 of 1

imagemagick'a modulateimage and windows7 problem

Posted: 2011-03-30T03:07:11-07:00
by poplintwist
Hi,
I'm working on image editing application using GTK+ and imagemagick. Everything was fine when I was running my app on Linux or win XP, but when I run it on win7 something strange happens. MagickCore's modulateImage method adds horizontal lines to the image. Example image:
Image

turns into:
Image

Here is minimal working code:

Code: Select all

#include <gtk/gtk.h>
#include <iostream>
#include <wand/MagickWand.h>

int main( int argc, char *argv[])
{
  gtk_init(&argc, &argv);

  GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

    GError* error=NULL;
    GdkPixbuf* _pixbuf = gdk_pixbuf_new_from_file("gps-photolinkfountain2.jpg",&error);
    if (error != NULL) exit(1);

    Image *magickImage;
    ExceptionInfo ex;
    GetExceptionInfo(&ex);

    guchar* _pixels = gdk_pixbuf_get_pixels(_pixbuf);
    int _w = gdk_pixbuf_get_width(_pixbuf);
    int _h = gdk_pixbuf_get_height(_pixbuf);

    magickImage = ConstituteImage(_w,_h,"RGB",CharPixel,_pixels,&ex);

    if (ex.severity != UndefinedException) CatchException(&ex);
    if (magickImage == (Image *) NULL) exit(1);

//!Modulate makes unexpected effect
    ModulateImage(magickImage,"100,100,100");
//!SigmoidalContrast works fine
//    SigmoidalContrastImage(magickImage,(MagickBooleanType)true,"40");

    ExportImagePixels( magickImage, 0, 0, _w, _h, "RGB", CharPixel, _pixels, &ex );
    if(ex.severity != UndefinedException) CatchException(&ex);

  GtkWidget *image = gtk_image_new_from_pixbuf (_pixbuf);
  gtk_container_add(GTK_CONTAINER(window), image);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), G_OBJECT(window));

  gtk_widget_show_all(window);
  gtk_main();
}

Strange thing is that other methods like SigmoidalContrastImage work fine.
It does not matter if I compile my application on winXP and migrate executable file to win7 or compile it on win7.

My System:
  • Windows 7 Professional 32-bit
  • Intel Atom N450
My Development toolkit:
  • GTK+2.2 - I have tried other versions.
  • Code::Blocks 10.05 with integrated MinGW
An the question is:
Am I doing something wrong (and maybe how to fix it) or is it a Imagemagick's or win7 bug?

Best regards
Sebastian

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-03-30T06:49:55-07:00
by magick
Let's see if its an OpenMP problem under Windows 7. Add
  • MagickCoreGenesis(*argv,MagickTrue);
    SetMagickResourceLimit(ThreadResource,1);
Before the call to ConstituteImage(); Does that fix the problem?

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-03-30T08:59:20-07:00
by poplintwist
Thanks for fast reply.
Effect of adding this code:

Code: Select all

    MagickCoreGenesis(*argv,MagickTrue);
    SetMagickResourceLimit(ThreadResource,1);
is:

Image

Now image has got one big red stripe, when function

Code: Select all

    ModulateImage(magickImage,"100,100,100");
should not change anything, so this problem is still open.

Sebastian

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-03-30T09:47:57-07:00
by magick
It points to a problem with OpenMP under Win 7. Does -modulate work properly from the command line (e.g. convert myimage -modulate ...)? Also try another image other than gps-photolinkfountain2.jpg. Does the problem still occur?

Next, add WriteImage() and write the image to gps-photolinkfountain2.png and display that with a Windows application to ensure GTK is not corrupting the image.

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-03-31T02:48:12-07:00
by poplintwist
Does -modulate work properly from the command line (e.g. convert myimage -modulate ...)?
From command line IM works properly.
Also try another image other than gps-photolinkfountain2.jpg. Does the problem still occur?
Problem still occurs.
add WriteImage() and write the image to gps-photolinkfountain2.png and display that with a Windows application to ensure GTK is not corrupting the image.
WriteImage() writes the same image that we can see in GTK window (with "red effect").

Sebastian

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-04-05T00:33:10-07:00
by pbarczyn
I have the same problem.

Does anyone have any solution for this?

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2011-04-05T08:31:47-07:00
by el_supremo
FYI: I compiled and ran this code and it works fine:

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(void)
{
	MagickWand *mw = NULL;
	MagickWandGenesis();

	mw = NewMagickWand();
	MagickReadImage(mw,"fountain.jpg");
	MagickModulateImage(mw,100,100,100);
	MagickWriteImage(mw,"fountain_mod.jpg");

	if(mw)mw = DestroyMagickWand(mw);
	MagickWandTerminus();
}
This is using IM 6.6.8-6 2011-03-21 Q16 OPENMP on Win7 Pro 64-bit i7-970 and 24GB of ram.

@poplintwist: Can you try the above code?

Pete

Re: imagemagick'a modulateimage and windows7 problem

Posted: 2013-04-25T15:32:03-07:00
by tom
Hello,

I know this is an old thread but I've just come across exactly the same problem - when calling MagickModulateImage, the image gets distorted by the horizontal red stripes. Convert -modulate works fine.

I've already tested a few different versions, but the problem appears on each of them (haven't tried all of them though)...

EDIT: In my case this happens on WinXP!

Thanks in advance for your advice,
Tom