2

I made a question on Stack Overflow and then tried to edit it so that what I entered in the entry box was the exact text shown below in the code block.

The system would not let me post it, throwing an error about my post looking like it contained improperly formatted code. By editing it in pieces, I narrowed it down so by adding an empty line between [![Difference][2]][2] and [![Distribution][3]][3] at the bottom I was able to post. All the images were added using the "image" button in the toolbar.

I think this may be a bug, and I didn't want to end up posting a duplicate question so I did not try it again after I got it to work.

I downloaded a test image from Wikipedia (the tree seen below) to compare `Pillow` and `OpenCV` (using `cv2`) in Python. Perceptually the two images appear the same, but their respective `md5` hashes don't match; and if I subtract the two images the result is not even close to solid black (the image shown below the original). The original image is a JPEG. If I convert it to a PNG first, the hashes match.

The last image shows the frequency distribution of how the pixel value differences.

This is the code I used:

    from PIL import Image
    import cv2
    import sys
    import md5
    import numpy as np

    def hashIm(im):
        im = cv2.imread(im)
        imP = np.array(Image.open(im))

        # Convert to BGR and drop alpha channel if it exists
        imP = imP[..., 2::-1]
        # Make the array contiguous again
        imP = np.array(imP)

        cv2.imshow('cv2', im)
        cv2.imshow('PIL', imP)
        cv2.imshow('diff', (im-imP))

        with open('dist.csv', 'w') as outfile:
            diff = im-imP
            for i in range(1, 256):
                outfile.write('{},{}\n'.format(i, np.count_nonzero(diff==i)))

        cv2.waitKey(0)
        cv2.destroyAllWindows()

        return md5.md5(im).hexdigest() + '   ' + md5.md5(imP).hexdigest()

    if __name__ == '__main__':
        print sys.argv[1] + '\t' + hashIm(sys.argv[1])

[![Original (Wikipedia "Tree" article)][1]][1]
[![Difference][2]][2]
[![Distribution][3]][3]

  [1]: https://i.stack.imgur.com/iWUnD.jpg
  [2]: https://i.stack.imgur.com/UNNtB.png
  [3]: https://i.stack.imgur.com/Vk0Y8.png
1

Just put a horizontal ruler after the code:

    if __name__ == '__main__':
        print sys.argv[1] + '\t' + hashIm(sys.argv[1])

--------------------------------------------

[![Original (Wikipedia "Tree" article)][1]][1]
[![Difference][2]][2]
[![Distribution][3]][3]


  [1]: https://i.stack.imgur.com/iWUnD.jpg
  [2]: https://i.stack.imgur.com/UNNtB.png
  [3]: https://i.stack.imgur.com/Vk0Y8.png

The same applies for continuing after code with lists or citation blocks IIRC.


That should render well as intended:

I downloaded a test image from Wikipedia (the tree seen below) to compare Pillow and OpenCV (using cv2) in python. Perceptually the two images appear the same, but their respective md5 hashes don't match; and if I subtract the two images the result is not even close to solid black (the image shown below the original). The original image is a JPEG. If I convert it to a PNG first, the hashes match.

The last image shows the frequency distribution of how the pixel value differences.

This is the code I used:

   from PIL import Image
   import cv2
   import sys
   import md5
   import numpy as np

   # more code ...

Original (Wikipedia "Tree" article) Difference Distribution

  • This didn't work for me. I clicked "Ask Question" and pasted the original, then added the horizontal rule (the error popped up without having to click "Post"). – chew socks Apr 22 '18 at 21:32
  • @chewsocks Hmm, it worked well for me here (as you can see), it also worked in the 1st version (without the cites). – πάντα ῥεῖ Apr 22 '18 at 21:34
  • Odd, it does actually render the preview for me. It just wouldn't let me post it – chew socks Apr 22 '18 at 21:40
  • Did you try it on Stack Overflow specifically? If I try to create the same question on meta.stackexchange then I get no complaint. – chew socks Apr 22 '18 at 21:41
  • @chewsocks Unfortunately I cannot try that at SO ATM. But if that's specific for SO, you probably should ask at their Meta site. – πάντα ῥεῖ Apr 22 '18 at 21:43
  • I didn't know they have their own Meta. But I just found it, so I'll do that. – chew socks Apr 22 '18 at 22:21
  • @chewsocks Every site in the SE network has it's own specific Meta site. Posts should go here only for network wide questions. – πάντα ῥεῖ Apr 22 '18 at 22:22
  • I've made one over there. I didn't actually know until a couple comments ago that it was specific to stackoverflow.com (even the checker on meta.stackoverflow.com doesn't complain. – chew socks Apr 22 '18 at 22:29
  • I'm not sure of the exact protocol, which option would be appropriate for flagging this question since I made a new on on meta.stackoverflow.com? – chew socks Apr 22 '18 at 22:31
  • @chewsocks You may delete this one, but even if you don't I don't see any harm done so far. – πάντα ῥεῖ Apr 22 '18 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .