サンプルコード
以下のサンプルコードでは、scikit-imageのthreshold_otsu/threshold_isodataでしきい値を求め、それぞれのアルゴリズムで2値化のRGB版と白黒版の動画を出力しています。from moviepy.editor import *
from skimage.filters import *
from skimage.color import *
def process_threshold_otsu(image):
threshold = threshold_otsu(image)
return (image > threshold)*255
def process_threshold_otsu_gray(image):
gray = rgb2gray(image)
threshold = threshold_otsu(gray)
return gray2rgb((gray > threshold)*255)
def process_threshold_iso(image):
threshold = threshold_isodata(image)
return (image > threshold)*255
def process_threshold_iso_gray(image):
gray = rgb2gray(image)
threshold = threshold_isodata(gray)
return gray2rgb((gray > threshold)*255)
clip1 = VideoFileClip("hydrangea.mp4")
clip1t = clip1.fl_image(process_threshold_otsu)
clip1t.write_videofile("process_threshold_otsu.mp4")
clip1t = clip1.fl_image(process_threshold_otsu_gray)
clip1t.write_videofile("process_threshold_otsu_gray.mp4")
clip1t = clip1.fl_image(process_threshold_iso)
clip1t.write_videofile("process_threshold_iso.mp4")
clip1t = clip1.fl_image(process_threshold_iso_gray)
clip1t.write_videofile("process_threshold_iso_gray.mp4")
〇元動画の画面

〇出力動画の画面(threshold_otsu)

〇出力動画の画面(rgb2grayとthreshold_otsu)

〇出力動画の画面(threshold_isodata)

〇出力動画の画面(rgb2grayとthreshold_isodata)

〇scikit-imageインストール
MoviePyの他、仮想環境のフォルダに移動して以下のコマンドを実行します。
pipenv install scikit-image
関連情報
・MoviePyのまとめ・moviepyのホームページ
https://zulko.github.io/moviepy/
0 件のコメント:
コメントを投稿