Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例_第1頁
Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例_第2頁
Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例_第3頁
Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例_第4頁
Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第Python實(shí)現(xiàn)圖片色彩轉(zhuǎn)換案例def_check_format(image_path:str):

ext=os.path.basename(image_path).strip().split('.')[-1]

ifextnotin['png','jpg']:

raiseException('formaterror')

returnext

代碼說明

1、兩個(gè)方法入?yún)⒕鶠椋簣D片路徑、輸出目錄路徑。

2、為了避免文件名重復(fù),使用uuid作為文件名。

3、圖片的后綴格式判斷只有兩種,如需增加,自行添加即可。

驗(yàn)證一下

圖片準(zhǔn)備,原圖如下:

驗(yàn)證代碼

if__name__=='__main__':

print(black_and_white('C:/Users/huyi/Desktop/4.jpg','C:/Users/huyi/Desktop/'))

print(brown('C:/Users/huyi/Desktop/4.jpg','C:/Users/huyi/Desktop/'))

執(zhí)行結(jié)果

PyDevconsole:starting.

Python3.6.13|Anaconda,Inc.|(default,Mar162025,11:37:27)[MSCv.191664bit(AMD64)]onwin32

runfile('D:/spyder/csdn/image_change_color_tool.py',wdir='D:/spyder/csdn')

ffmpeg-iC:/Users/huyi/Desktop/4.jpg-vfcolorchannelmixer=.3:.4:.3:0:.3:.4:.3:0:.3:.4:.3-yC:/Users/huyi/Desktop/c7052ed8-d5db-4e84-9c01-88d661c967a5.jpg

ffmpegversionn4.3.1-20-g8a2acdc6daCopyright(c)2000-2025theFFmpegdevelopers

builtwithgcc9.3-win32(GCC)20250320

configuration:--prefix=/ffbuild/prefix--pkg-config-flags=--static--pkg-config=pkg-config--cross-prefix=x86_64-w64-mingw32---arch=x86_64--target-os=mingw32--enable-gpl--enable-version3--disable-debug--enable-iconv--enable-zlib--enable-libxml2--enable-libfreetype--enable-libfribidi--enable-gmp--enable-lzma--enable-fontconfig--enable-libvmaf--disable-vulkan--enable-libvorbis--enable-amf--enable-libaom--enable-avisynth--enable-libdav1d--enable-ffnvcodec--enable-cuda-llvm--disable-libglslang--enable-libass--enable-libbluray--enable-libmp3lame--enable-libopus--enable-libtheora--enable-libvpx--enable-libwebp--enable-libmfx--enable-libopencore-amrnb--enable-libopencore-amrwb--enable-libopenjpeg--enable-librav1e--enable-schannel--enable-sdl2--enable-libsoxr--enable-libsrt--enable-libtwolame--enable-libvidstab--enable-libx264--enable-libx265--enable-libxvid--enable-libzimg--extra-cflags=-DLIBTWOLAME_STATIC--extra-cxxflags=--extra-ldflags=-pthread--extra-libs=-lgomp

libavutil56.51.100/56.51.100

libavcodec58.91.100/58.91.100

libavformat58.45.100/58.45.100

libavdevice58.10.100/58.10.100

libavfilter7.85.100/7.85.100

libswscale5.7.100/5.7.100

libswresample3.7.100/3.7.100

libpostproc55.7.100/55.7.100

Input#0,image2,from'C:/Users/huyi/Desktop/4.jpg':

Duration:00:00:00.04,start:0.000000,bitrate:101138kb/s

Stream#0:0:Video:mjpeg(Progressive),yuvj444p(pc,bt470bg/unknown/unknown),1920x1080,25tbr,25tbn,25tbc

Streammapping:

Stream#0:0-#0:0(mjpeg(native)-mjpeg(native))

Press[q]tostop,[]forhelp

[swscaler@000001625402e2c0]deprecatedpixelformatused,makesureyoudidsetrangecorrectly

[swscaler@0000016253b14f80]deprecatedpixelformatused,makesureyoudidsetrangecorrectly

Output#0,image2,to'C:/Users/huyi/Desktop/c7052ed8-d5db-4e84-9c01-88d661c967a5.jpg':

Metadata:

encoder:Lavf58.45.100

Stream#0:0:Video:mjpeg,yuvj444p(pc),1920x1080,q=2-31,200kb/s,25fps,25tbn,25tbc

Metadata:

encoder:Lavc58.91.100mjpeg

Sidedata:

cpb:bitratemax/min/avg:0/0/200000buffersize:0vbv_delay:N/A

frame=1fps=0.0q=9.2Lsize=N/Atime=00:00:00.04bitrate=N/Aspeed=0.232x

video:133kBaudio:0kBsubtitle:0kBotherstreams:0kBglobalheaders:0kBmuxingoverhead:unknown

C:/Users/huyi/Desktop/c7052ed8-d5db-4e84-9c01-88d661c967a5.jpg

ffmpeg-iC:/Users/huyi/Desktop/4.jpg-vfcolorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131-yC:/Users/huyi/Desktop/9282f36a-2361-4b0d-a115-56864c9d2337.jpg

ffmpegversionn4.3.1-20-g8a2acdc6daCopyright(c)2000-2025theFFmpegdevelopers

builtwithgcc9.3-win32(GCC)20250320

configuration:--prefix=/ffbuild/prefix--pkg-config-flags=--static--pkg-config=pkg-config--cross-prefix=x86_64-w64-mingw32---arch=x86_64--target-os=mingw32--enable-gpl--enable-version3--disable-debug--enable-iconv--enable-zlib--enable-libxml2--enable-libfreetype--enable-libfribidi--enable-gmp--enable-lzma--enable-fontconfig--enable-libvmaf--disable-vulkan--enable-libvorbis--enable-amf--enable-libaom--enable-avisynth--enable-libdav1d--enable-ffnvcodec--enable-cuda-llvm--disable-libglslang--enable-libass--enable-libbluray--enable-libmp3lame--enable-libopus--enable-libtheora--enable-libvpx--enable-libwebp--enable-libmfx--enable-libopencore-amrnb--enable-libopencore-amrwb--enable-libopenjpeg--enable-librav1e--enable-schannel--enable-sdl2--enable-libsoxr--enable-libsrt--enable-libtwolame--enable-libvidstab--enable-libx264--enable-libx265--enable-libxvid--enable-libzimg--extra-cflags=-DLIBTWOLAME_STATIC--extra-cxxflags=--extra-ldflags=-pthread--extra-libs=-lgomp

libavutil56.51.100/56.51.100

libavcodec58.91.100/58.91.100

libavformat58.45.100/58.45.100

libavdevice58.10.100/58.10.100

libavfilter7.85.100/7.85.100

libswscale5.7.100/5.7.100

libswresample3.7.100/3.7.100

libpostproc55.7.100/55.7.100

Input#0,image2,from'C:/Users/huyi/Desktop/4.jpg':

Duration:00:00:00.04,start:0.000000,bitrate:101138kb/s

Stream#0:0:Video:mjpeg(Progressive),yuvj444p(pc,bt470bg/unknown/unknown),1920x1080,25tbr,25tbn,25tbc

Streammapping:

Stream#0:0-#0:0(mjpeg(native)-mjpeg(native))

Press[q]tostop,[]forhelp

[swscaler@0000013b05762f80]deprecatedpixelformatused,makesureyoudidsetrangecorrectly

[swscaler@0000013b052c4fc0]deprecatedpixelformatused,makesureyoudidsetrangecorrectly

Output#0,image2,to'C:/Users/huyi/Desktop/9282f36a-2361-4b0d-a115-568

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論