Page 1 of 1

can't get the similarity image

Posted: 2014-04-22T10:31:45-07:00
by wbaccari
I have created two jped images and I am trying to get the similarity image from them using MagickCore.

This is the full code:

Code: Select all

#include <string.h>
#include "ImageMagick-6/magick/MagickCore.h"

int main()
{
  ExceptionInfo     *exception;
  Image             *base_image, *reference_image, *composed_image;
  double            similarity;
  RectangleInfo     offset;
  ImageInfo         *image_info_base, *image_info_reference, *image_info_composed;

  char base_image_src[] = "in1.jpeg";
  char reference_image_src[] = "in2.jpeg";
  char composed_image_dst[] = "out.jpeg";

  MagickCoreGenesis(NULL, MagickTrue);
  exception = AcquireExceptionInfo();

  image_info_base = CloneImageInfo((ImageInfo *) NULL);
  (void) strcpy(image_info_base->filename, base_image_src);
  base_image = ReadImage(image_info_base, exception);
  CatchException(exception);

  image_info_reference = CloneImageInfo((ImageInfo *) NULL);
  (void) strcpy(image_info_reference->filename, reference_image_src);
  reference_image = ReadImage(image_info_reference, exception);
  CatchException(exception);

  composed_image = SimilarityImage(base_image, reference_image, &offset, &similarity, exception);
  CatchException(exception);

  printf("%f\n", similarity);
  printf("w %d h %d x %d y %d\n", (int) offset.width, (int) offset.height, (int) offset.x, (int) offset.y);

  strcpy(composed_image->filename, composed_image_dst);
  composed_image->x_resolution = 256;
  composed_image->y_resolution = 256;
  composed_image->rows = 256;
  composed_image->columns = 256;

  image_info_composed = CloneImageInfo((ImageInfo *) NULL);

  if (WriteImage(image_info_composed, composed_image) == MagickTrue)
    printf("image saved to disk\n");
  CatchException(&composed_image->exception);
  
  exception = DestroyExceptionInfo(exception);
  MagickCoreTerminus();
  return 0;
}
These are the input images:
Image & Image

I keep getting a black image with only one grey pixel at the top left corner
Image

What am I doing wrong?

Re: can't get the similarity image

Posted: 2014-04-22T10:36:36-07:00
by fmw42
You can only get a meaningful similarity image when using a small image and a large image, by using the equivalent of -subimage-search in compare. Then the similarity image shows you the match value at each shift position of the small image relative to the larger image. If the two images are the same size, you get a one pixel similarity image, since there is only one relative position between the two images.

Sorry I do not know the API equivalent.

see
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076

but that syntax now needs -subimage-search to be included.

Re: can't get the similarity image

Posted: 2014-04-23T02:22:17-07:00
by wbaccari
I understand now. Thanks Fred!