0

I have been fighting with this for a while without any luck. I am converting a pdf using wand library (ImageMagick) in python and calculating the features using open cv2 for later on some other image matching. The is the following

from wand.image import Image
import cv2 as cv
import logging

with Image(filename="processing.pdf[0]", resolution=500) as img:
    img.compression_quality = 100
    img.format = "png"
    img.save(filename="temp.png")

detector = cv.BRISK_create()

img1 = cv.imread("temp.png", 0)

kp1, desc1 = detector.detectAndCompute(img1, None)

logging.warn('img1 - %{0} features'.format(len(kp1)))

For some reason I get different number of features in windows and linux Windows

2018-08-22 01:45:21,235 - INFO - img1 - %44509 features

Linux

2018-08-22 05:41:54,891 - INFO - img1 - %48371 features

I am using the following dependency in python

opencv-python==3.4.0
Wand==0.4.4

ImageMagick 6.8.9 installed.

If I use the same image (copy the image from windows machine to linux machine) and execute the code without converting PDF, the number of features is almost the same.

I know there are differences between the linux/windows codecs however I am looking for a decent solution or workaround to make the behavior as close as possible to between both environments. Thanks in advance.

hlagos
  • 7,690
  • 3
  • 23
  • 41
  • 2
    You may have differing versions of **ghostscript** which **ImageMagick** uses to read PDFs. I think you should maybe omit compression quality for PNGs as it's always lossless. Also check image has same number of channels and same mean/stddev before and after saving - those flags on `cv2.imread()` are hard to get right. – Mark Setchell Aug 22 '18 at 16:13
  • You could also run **ImageMsgick**'s `compare` on `temp.png` from Windows versus that produced on Linux... – Mark Setchell Aug 22 '18 at 16:15
  • @MarkSetchell thank you for your suggestion. After run the ImageMagick's compare I get an output image, so do images are definitely different depending on where I am generating them. I also tried removing compression quality geting the same behavior. I tried setting colorspace to img.colorspace = 'rgb' getting the same results. Any other suggestions would be really appreciate it. I am using the same ImageMagick version in both sides. – hlagos Aug 22 '18 at 17:32
  • Ghostscript device rendering would most likely be the cause. Try running the `gs` utility directly on each box, and use Mark's `compare` technique to isolate the difference. A resolution of 500 is rather large, and the [smallest artifact](https://en.wikipedia.org/wiki/Compression_artifact) could become exaggerated. – emcconville Aug 22 '18 at 18:48

0 Answers0