1 / 2

Problem 9

Problem 9. 請將輸入的影像 ”prob9.jpg” 轉為黑白影像。 請定義一個 函數,叫做 BW( infile ) ,此函數必須執行以下部分 : 開啟 infile 同時展現 infile 。 將輸入檔案 改成 rgb 格式。 讀入每 一個 pixel 的 r,g,b 值,計算出此三術的平均值,然後將此平均值存回 r,g,b 將影像存為原檔名,並加入 _ bw 於名中,也就是 prob9.jpg 改成 prob9_bw.jpg ,並將改後的黑白相片存於其中,同時再次展現相片。. Problem 9.

Download Presentation

Problem 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problem 9 請將輸入的影像”prob9.jpg”轉為黑白影像。 請定義一個函數,叫做BW(infile),此函數必須執行以下部分: 開啟infile同時展現infile。 將輸入檔案改成rgb格式。 讀入每一個pixel的r,g,b值,計算出此三術的平均值,然後將此平均值存回r,g,b 將影像存為原檔名,並加入_bw於名中,也就是prob9.jpg改成prob9_bw.jpg,並將改後的黑白相片存於其中,同時再次展現相片。

  2. Problem 9 0. Import PIL from PIL import Image 開啟infile同時展現infile。 myImage = Image.open(infile) Image.show() 將輸入檔案改成rgb格式。 myImage=myImage.convert(‘RGB’) 讀入每一個pixel的r,g,b值,計算出此三術的平均值,然後將此平均值存回r,g,b 要讀入前需要知道影像的尺寸,讀出及存入某pixel之顏色 width, height = myImage.size r,g,b = myImage.getpixel((x,y)) myImage.putpixel((x,y), (r,g,b)) 將影像存為原檔名,並加入_bw於名中,也就是prob9.jpg改成prob9_bw.jpg,並將改後的黑白相片存於其中,同時再次展現相片。 myImage.save(outfile)

More Related