# ラベリング library(imager) # グレースケール画像 im <- grayscale(load.example("coins")) # 2値化 im.bin <- threshold(im, "auto") # ラベリング x <- label(im.bin) # ラベル付けされた図形の面積(画素数) areas <- table(x) # 面積が100以上の図形のラベルと面積を出力 print(areas[areas >= 100]) # ラベルを指定して図形を抜き出す im.ex <- im im.ex[x != 113 & x != 238] <- 1 layout(t(1 : 2)) plot(im, main = "元画像") plot(im.ex, main = "抜き出した図形") layout(1)