简体   繁体   中英

How to fill polygon in image

I've a closed contour region on an image. How to fill it up with white color? Not sure whats the Julia function for fillpoly(..)? Thanks

black background img with thin white circle, contour=findall(img.>0) img_With_contour_filled_with_white=..

Original Img Filled Img
在此处输入图像描述 在此处输入图像描述
在此处输入图像描述 在此处输入图像描述
在此处输入图像描述 在此处输入图像描述
在此处输入图像描述 在此处输入图像描述

code:

using Images

img = load("img.png")

function fill_poly!(img::Matrix{RGB{N0f8}})
  bit_cols = all.(==(RGB(1., 1., 1.)), eachcol(img)) .== 0
  idx_cols = findall(bit_cols)
  f = findfirst.(!=(RGB(1., 1., 1.)), eachcol(img[:, bit_cols]))
  l = findlast.(!=(RGB(1., 1., 1.)), eachcol(img[:, bit_cols]))
  foreach(x->img[x[1]:x[2], x[3]].=RGB(0., 0., 0.), zip(f, l, idx_cols))
end;

fill_poly!(img)

Known issue: fills areas like the following
在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM