Problem Record | recording of a pit PIL in Image.save

Image.save values ​​are then open to become

I looked all afternoon and finally to identify the problems, there is a local after a PIL Image library to resize the picture and then read in, and the value after direct resize is not the same.

data_val:
 [[[[175 104  78]
   [174 102  77]
   [178 106  81]

resize_progress: 
[[[175 104  78]
  [174 102  77]
  [178 106  81]
  ...

IMG_read_again resize_progress:
 [[[182 105  75]
  [182 105  75]
  [182 105  75]
  ...

Array too long, just put part of the blog.
Function is written as follows:

    def resize_img(self, img_path):
        dirname = os.path.dirname(img_path)
        img_basename=os.path.basename(img_path)
        tmp_dir = os.path.join(dirname,'resize/')
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)
        img = Image.open(img_path)
        img = img.resize((self.img_row, self.img_col), Image.ANTIALIAS)
        print("resize_progress:",np.array(img))
        resize_img_path = os.path.join(tmp_dir,img_basename)
        img.save(resize_img_path)
        self.img_path = resize_img_path
        IMG_read_again = Image.open(resize_img_path)
        print("IMG_read_again resize_progress:\n",np.array(IMG_read_again))
        return resize_img_path

Guess you like

Origin www.cnblogs.com/ManWingloeng/p/11537192.html