# 輪郭抽出(前進差分) library(imager) # グレースケール画像 im <- grayscale(boats) # x方向の前進差分のフィルタ f.fx <- as.cimg(c(0, 0, 0, 0, -1, 1, 0, 0, 0), x = 3, y = 3) # y方向の前進差分のフィルタ f.fy <- as.cimg(c(0, 0, 0, 0, -1, 0, 0, 1, 0), x = 3, y = 3) # 畳み込み演算 im.fx = correlate(im, f.fx) im.fy = correlate(im, f.fy) # 同時に4枚並べるレイアウト layout(t(1 : 4)) plot(im, main = "元の画像") plot(im.fx, main = "x方向の前進差分") plot(im.fy, main = "y方向の前進差分") plot(sqrt(im.fx ^ 2 + im.fy ^ 2), main = "輪郭の強さ") # レイアウトを元に戻す layout(1)