Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在使用PIL将CMYK图像转换为RGB时保持相同的颜色?_Python_Image_Image Processing_Python Imaging Library_Jpeg - Fatal编程技术网

Python 如何在使用PIL将CMYK图像转换为RGB时保持相同的颜色?

Python 如何在使用PIL将CMYK图像转换为RGB时保持相同的颜色?,python,image,image-processing,python-imaging-library,jpeg,Python,Image,Image Processing,Python Imaging Library,Jpeg,将CMYK图像转换为RGB时,我的颜色会反转。我想保持相同的(视觉)颜色并删除exif数据 我需要这样做才能在任何图像或pdf查看器上显示转换后的图像 结果(代码如下) 原始CMYK 图像太重,无法上载-> 转换RGB 取消注释后转换的RGB反转像素(图像) 使用转换(此转换在PDF和其他图像查看器中正常工作。我希望基本上重新创建此图像配置文件) 堆栈 Python 3.5.9 PIL 5.1.0 测试代码: image\u filename=“original.jpeg” image

将CMYK图像转换为RGB时,我的颜色会反转。我想保持相同的(视觉)颜色并删除exif数据

我需要这样做才能在任何图像或pdf查看器上显示转换后的图像

结果(代码如下) 原始CMYK 图像太重,无法上载->

转换RGB

取消注释后转换的RGB
反转像素(图像)

使用转换(此转换在PDF和其他图像查看器中正常工作。我希望基本上重新创建此图像配置文件)

堆栈
  • Python 3.5.9
  • PIL 5.1.0
测试代码:
image\u filename=“original.jpeg”
image\u file=open(image\u文件名,“rb”)
image=image.open(图像文件)
使用exif(图像)定位图像
image\u data=list(image.getdata())
image_不带_exif=image.convert(“RGB”)
不带exif.putdata的图像(图像数据)
#反转像素(图像)
不带exif.save的图像(
格式(图像文件名),
渐进=正确,
icc_profile=image.info.get('icc_profile'),
二次抽样=0,
)
评论
  • 我转换为RGB只是因为TinyJPG图像的元数据显示它是RGB
  • 考虑到像素反转离我有多近,我的猜测是我需要为每个像素转换找到正确的公式来保持正确的颜色
  • 使用_exif确定_图像的方向
    对最终颜色没有影响
问题:
  • 有人能帮我让它正常工作吗?期望的结果类似于TinyJPG图像。它确实进行无损压缩。我不想/不在乎那件事。我只对删除exif数据(有效)和保持正确的颜色(无效)感兴趣

    • 我不知道你在这里干什么。我得到了一个正确的彩色,带此代码的图像:

      from PIL import Image
      
      im = Image.open('original.jpg')
      RGB = im.convert('RGB')
      RGB.save('result.jpg')
      
      我可以通过
      exiftool
      看到原件中的“ICC配置文件”,如下所示:

      exiftool original.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : original.jpg
      Directory                       : .
      File Size                       : 5.1 MB
      File Modification Date/Time     : 2020:11:27 12:08:27+00:00
      File Access Date/Time           : 2020:11:27 12:09:49+00:00
      File Inode Change Date/Time     : 2020:11:27 12:08:43+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      DCT Encode Version              : 100
      APP14 Flags 0                   : (none)
      APP14 Flags 1                   : (none)
      Color Transform                 : Unknown (RGB or CMYK)
      Profile CMM Type                : Adobe Systems Inc.
      Profile Version                 : 2.1.0
      Profile Class                   : Output Device Profile
      Color Space Data                : CMYK
      Profile Connection Space        : Lab
      Profile Date Time               : 2000:07:26 05:41:53
      Profile File Signature          : acsp
      Primary Platform                : Apple Computer Inc.
      CMM Flags                       : Not Embedded, Independent
      Device Manufacturer             : Adobe Systems Inc.
      Device Model                    : 
      Device Attributes               : Reflective, Glossy, Positive, Color
      Rendering Intent                : Perceptual
      Connection Space Illuminant     : 0.9642 1 0.82491
      Profile Creator                 : Adobe Systems Inc.
      Profile ID                      : 0
      Profile Description             : U.S. Web Coated (SWOP) v2
      Profile Copyright               : Copyright 2000 Adobe Systems, Inc.
      Media White Point               : 0.7084 0.73595 0.57104
      A To B0                         : (Binary data 41478 bytes, use -b option to extract)
      A To B2                         : (Binary data 41478 bytes, use -b option to extract)
      A To B1                         : (Binary data 41478 bytes, use -b option to extract)
      B To A0                         : (Binary data 145588 bytes, use -b option to extract)
      B To A1                         : (Binary data 145588 bytes, use -b option to extract)
      B To A2                         : (Binary data 145588 bytes, use -b option to extract)
      Gamut                           : (Binary data 37009 bytes, use -b option to extract)
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 4
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      exiftool result.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : result.jpg
      Directory                       : .
      File Size                       : 718 kB
      File Modification Date/Time     : 2020:11:27 12:15:48+00:00
      File Access Date/Time           : 2020:11:27 12:16:14+00:00
      File Inode Change Date/Time     : 2020:11:27 12:15:54+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      JFIF Version                    : 1.01
      Resolution Unit                 : None
      X Resolution                    : 1
      Y Resolution                    : 1
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 3
      Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      我可以在输出文件中看到它如下所示:

      exiftool original.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : original.jpg
      Directory                       : .
      File Size                       : 5.1 MB
      File Modification Date/Time     : 2020:11:27 12:08:27+00:00
      File Access Date/Time           : 2020:11:27 12:09:49+00:00
      File Inode Change Date/Time     : 2020:11:27 12:08:43+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      DCT Encode Version              : 100
      APP14 Flags 0                   : (none)
      APP14 Flags 1                   : (none)
      Color Transform                 : Unknown (RGB or CMYK)
      Profile CMM Type                : Adobe Systems Inc.
      Profile Version                 : 2.1.0
      Profile Class                   : Output Device Profile
      Color Space Data                : CMYK
      Profile Connection Space        : Lab
      Profile Date Time               : 2000:07:26 05:41:53
      Profile File Signature          : acsp
      Primary Platform                : Apple Computer Inc.
      CMM Flags                       : Not Embedded, Independent
      Device Manufacturer             : Adobe Systems Inc.
      Device Model                    : 
      Device Attributes               : Reflective, Glossy, Positive, Color
      Rendering Intent                : Perceptual
      Connection Space Illuminant     : 0.9642 1 0.82491
      Profile Creator                 : Adobe Systems Inc.
      Profile ID                      : 0
      Profile Description             : U.S. Web Coated (SWOP) v2
      Profile Copyright               : Copyright 2000 Adobe Systems, Inc.
      Media White Point               : 0.7084 0.73595 0.57104
      A To B0                         : (Binary data 41478 bytes, use -b option to extract)
      A To B2                         : (Binary data 41478 bytes, use -b option to extract)
      A To B1                         : (Binary data 41478 bytes, use -b option to extract)
      B To A0                         : (Binary data 145588 bytes, use -b option to extract)
      B To A1                         : (Binary data 145588 bytes, use -b option to extract)
      B To A2                         : (Binary data 145588 bytes, use -b option to extract)
      Gamut                           : (Binary data 37009 bytes, use -b option to extract)
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 4
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      exiftool result.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : result.jpg
      Directory                       : .
      File Size                       : 718 kB
      File Modification Date/Time     : 2020:11:27 12:15:48+00:00
      File Access Date/Time           : 2020:11:27 12:16:14+00:00
      File Inode Change Date/Time     : 2020:11:27 12:15:54+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      JFIF Version                    : 1.01
      Resolution Unit                 : None
      X Resolution                    : 1
      Y Resolution                    : 1
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 3
      Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      

      关键词:图像处理、Python、PIL、枕头、EXIF、条带EXIF、配置文件、ICC配置文件、条带配置文件。

      我不知道您在这里做什么。我得到了一个正确的彩色,带此代码的图像:

      from PIL import Image
      
      im = Image.open('original.jpg')
      RGB = im.convert('RGB')
      RGB.save('result.jpg')
      
      我可以通过
      exiftool
      看到原件中的“ICC配置文件”,如下所示:

      exiftool original.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : original.jpg
      Directory                       : .
      File Size                       : 5.1 MB
      File Modification Date/Time     : 2020:11:27 12:08:27+00:00
      File Access Date/Time           : 2020:11:27 12:09:49+00:00
      File Inode Change Date/Time     : 2020:11:27 12:08:43+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      DCT Encode Version              : 100
      APP14 Flags 0                   : (none)
      APP14 Flags 1                   : (none)
      Color Transform                 : Unknown (RGB or CMYK)
      Profile CMM Type                : Adobe Systems Inc.
      Profile Version                 : 2.1.0
      Profile Class                   : Output Device Profile
      Color Space Data                : CMYK
      Profile Connection Space        : Lab
      Profile Date Time               : 2000:07:26 05:41:53
      Profile File Signature          : acsp
      Primary Platform                : Apple Computer Inc.
      CMM Flags                       : Not Embedded, Independent
      Device Manufacturer             : Adobe Systems Inc.
      Device Model                    : 
      Device Attributes               : Reflective, Glossy, Positive, Color
      Rendering Intent                : Perceptual
      Connection Space Illuminant     : 0.9642 1 0.82491
      Profile Creator                 : Adobe Systems Inc.
      Profile ID                      : 0
      Profile Description             : U.S. Web Coated (SWOP) v2
      Profile Copyright               : Copyright 2000 Adobe Systems, Inc.
      Media White Point               : 0.7084 0.73595 0.57104
      A To B0                         : (Binary data 41478 bytes, use -b option to extract)
      A To B2                         : (Binary data 41478 bytes, use -b option to extract)
      A To B1                         : (Binary data 41478 bytes, use -b option to extract)
      B To A0                         : (Binary data 145588 bytes, use -b option to extract)
      B To A1                         : (Binary data 145588 bytes, use -b option to extract)
      B To A2                         : (Binary data 145588 bytes, use -b option to extract)
      Gamut                           : (Binary data 37009 bytes, use -b option to extract)
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 4
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      exiftool result.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : result.jpg
      Directory                       : .
      File Size                       : 718 kB
      File Modification Date/Time     : 2020:11:27 12:15:48+00:00
      File Access Date/Time           : 2020:11:27 12:16:14+00:00
      File Inode Change Date/Time     : 2020:11:27 12:15:54+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      JFIF Version                    : 1.01
      Resolution Unit                 : None
      X Resolution                    : 1
      Y Resolution                    : 1
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 3
      Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      我可以在输出文件中看到它如下所示:

      exiftool original.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : original.jpg
      Directory                       : .
      File Size                       : 5.1 MB
      File Modification Date/Time     : 2020:11:27 12:08:27+00:00
      File Access Date/Time           : 2020:11:27 12:09:49+00:00
      File Inode Change Date/Time     : 2020:11:27 12:08:43+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      DCT Encode Version              : 100
      APP14 Flags 0                   : (none)
      APP14 Flags 1                   : (none)
      Color Transform                 : Unknown (RGB or CMYK)
      Profile CMM Type                : Adobe Systems Inc.
      Profile Version                 : 2.1.0
      Profile Class                   : Output Device Profile
      Color Space Data                : CMYK
      Profile Connection Space        : Lab
      Profile Date Time               : 2000:07:26 05:41:53
      Profile File Signature          : acsp
      Primary Platform                : Apple Computer Inc.
      CMM Flags                       : Not Embedded, Independent
      Device Manufacturer             : Adobe Systems Inc.
      Device Model                    : 
      Device Attributes               : Reflective, Glossy, Positive, Color
      Rendering Intent                : Perceptual
      Connection Space Illuminant     : 0.9642 1 0.82491
      Profile Creator                 : Adobe Systems Inc.
      Profile ID                      : 0
      Profile Description             : U.S. Web Coated (SWOP) v2
      Profile Copyright               : Copyright 2000 Adobe Systems, Inc.
      Media White Point               : 0.7084 0.73595 0.57104
      A To B0                         : (Binary data 41478 bytes, use -b option to extract)
      A To B2                         : (Binary data 41478 bytes, use -b option to extract)
      A To B1                         : (Binary data 41478 bytes, use -b option to extract)
      B To A0                         : (Binary data 145588 bytes, use -b option to extract)
      B To A1                         : (Binary data 145588 bytes, use -b option to extract)
      B To A2                         : (Binary data 145588 bytes, use -b option to extract)
      Gamut                           : (Binary data 37009 bytes, use -b option to extract)
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 4
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      
      exiftool result.jpg
      
      ExifTool Version Number         : 12.00
      File Name                       : result.jpg
      Directory                       : .
      File Size                       : 718 kB
      File Modification Date/Time     : 2020:11:27 12:15:48+00:00
      File Access Date/Time           : 2020:11:27 12:16:14+00:00
      File Inode Change Date/Time     : 2020:11:27 12:15:54+00:00
      File Permissions                : rw-r--r--
      File Type                       : JPEG
      File Type Extension             : jpg
      MIME Type                       : image/jpeg
      JFIF Version                    : 1.01
      Resolution Unit                 : None
      X Resolution                    : 1
      Y Resolution                    : 1
      Image Width                     : 4167
      Image Height                    : 4167
      Encoding Process                : Baseline DCT, Huffman coding
      Bits Per Sample                 : 8
      Color Components                : 3
      Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
      Image Size                      : 4167x4167
      Megapixels                      : 17.4
      

      关键词:图像处理、Python、PIL、枕头、EXIF、条带EXIF、配置文件、ICC配置文件、条带配置文件。

      非常感谢您花时间和帮助。好的,看来主要的问题比我想象的要简单。只需将打开的图像转换为RGB,PDF查看器也可以正确显示它。但是,如果您将代码的结果与TinyJPG图像进行比较,颜色仍然不同。你知道如何解决这个问题吗?问题是配置文件正在影响颜色,一旦你删除它,它们就消失了,你需要一些东西来应用配置文件来修改颜色,然后在没有配置文件的情况下保存修改后的颜色。不知道该建议什么。非常感谢您抽出时间和帮助。好的,看来主要的问题比我想象的要简单。只需将打开的图像转换为RGB,PDF查看器也可以正确显示它。但是,如果您将代码的结果与TinyJPG图像进行比较,颜色仍然不同。你知道如何解决这个问题吗?问题是配置文件正在影响颜色,一旦你删除它,它们就消失了,你需要一些东西来应用配置文件来修改颜色,然后在没有配置文件的情况下保存修改后的颜色。不知道该建议什么。为什么要将图像转换为RGB?JPEG能够直接保存CMYK/YCCK图像。我正试图实现上一张图像中显示的内容。与上一幅图像的工作原理相同,将原始图像更改为RGB似乎可以使其在PDF查看器中工作。当使用PDF查看器打开原始CMYK图像时,会反转颜色。在将图像转换为RGB时,您还应删除icc_配置文件。顺便说一句,您共享的图像不包含Exif数据(APP1标记段)。是的,似乎不包含。这意味着问题在于如何在不同的阅读器中表现颜色空间。理想的解决方案是在视觉上保持与压缩的微小jpg图像相同的颜色为什么要将图像转换为RGB?JPEG能够直接保存CMYK/YCCK图像。我正试图实现上一张图像中显示的内容。与上一幅图像的工作原理相同,将原始图像更改为RGB似乎可以使其在PDF查看器中工作。当使用PDF查看器打开原始CMYK图像时,会反转颜色。在将图像转换为RGB时,您还应删除icc_配置文件。顺便说一句,您共享的图像不包含Exif数据(APP1标记段)。是的,似乎不包含。这意味着问题在于如何在不同的阅读器中表现颜色空间。理想的解决方案是在视觉上保持与压缩的微小jpg图像相同的颜色