请教各位大虾,PIL调用Img.histogram()的时候同一张图片('L')每次计算出来的Histogram list都不一样。
有没有人遇到过这种情况。
贴一下代码主要流程:
- # change to grey image
- im = Image.open(image)
- im_grey = im.convert('L')
- [color=Red]im.save(image)[/color]
- # calculate histogram for parts of the image
- im11_grey = im_grey.crop(im11_grey_box)
- histogram_11_grey = im11_grey.histogram()
- #
复制代码
奇怪的是我把im.save(image) 注释掉,结果就保持一样了。难道convert可以根据source image的变化来变化,难道save之后source image变了?
下面是同一张image,两次的Histogram()返回结果
请问是什么原因,如何解决呢?
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 2, 3, 2, 1, 5, 2, 4, 2, 2, 5, 4, 2, 7, 6, 6, 4, 4, 2, 4, 8, 3, 8, 3, 9, 13, 9, 9, 13, 12, 5, 14, 17, 14, 18, 20, 18, 20, 18, 26, 24, 28, 19, 21, 33, 25, 29, 41, 40, 46, 30, 47, 33, 42, 43, 43, 45, 45, 45, 66, 63, 66, 55, 51, 52, 44, 60, 55, 57, 58, 54, 67, 54, 55, 80, 79, 65, 63, 53, 50, 51, 68, 72, 62, 66, 60, 68, 107, 103, 72, 99, 88, 107, 184, 234, 247, 262, 493, 627, 703, 669, 308, 376, 296, 327, 254, 214, 126, 94, 68, 88, 95, 74, 156, 78, 144, 193, 204, 67, 74, 81, 89, 77, 92, 156, 178, 363, 352, 282, 358, 562, 501, 331, 363, 271, 130, 181, 83, 94, 187, 208, 89, 155, 157, 121, 78, 195, 77, 86, 125, 84, 89, 100, 106, 134, 368, 150, 337, 295, 473, 820, 1072, 943, 944, 1527, 2070, 5808, 19419]
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 2, 3, 3, 0, 5, 2, 4, 2, 3, 4, 4, 3, 7, 5, 6, 6, 2, 1, 6, 7, 5, 6, 3, 10, 12, 8, 12, 11, 11, 7, 14, 18, 13, 16, 21, 22, 14, 22, 24, 23, 28, 21, 23, 34, 22, 27, 40, 44, 44, 38, 33, 38, 43, 43, 46, 44, 45, 46, 64, 65, 58, 55, 54, 55, 44, 55, 57, 57, 60, 54, 66, 56, 62, 75, 72, 71, 59, 52, 53, 56, 60, 71, 69, 58, 64, 69, 140, 69, 75, 99, 90, 107, 170, 242, 225, 364, 495, 539, 651, 647, 379, 348, 406, 214, 320, 197, 114, 98, 75, 77, 98, 74, 134, 104, 90, 256, 196, 65, 77, 77, 89, 78, 91, 148, 161, 383, 388, 256, 389, 468, 618, 230, 392, 288, 125, 180, 84, 95, 190, 215, 79, 189, 144, 103, 75, 197, 79, 83, 127, 84, 91, 96, 109, 135, 365, 152, 340, 300, 529, 880, 1007, 938, 920, 1634, 2166, 5644, 19346]
复制代码 |