How can i fill NaN values on unwanted region of an image?

8 ビュー (過去 30 日間)
Don Max
Don Max 2022 年 6 月 29 日
編集済み: Don Max 2022 年 6 月 29 日
I am working on 3D reconstruction. Attaching captured fringe pattern here. Is that possible to fill NaN values on unwanted regions (regions where no measured object)?

採用された回答

Image Analyst
Image Analyst 2022 年 6 月 29 日
Not sure from your image where the unwanted regions are - you didn't indicate them. If you want, and it's appropriate you could use isnan and imcrop to crop away the unwanted regions from the outer parts of the image.
goodPixels = ~isnan(grayImage);
goodPixels = bwconvhull(goodPixels, 'union');
props = regionprops(goodPixels, 'BoundingBox');
grayImage = imcrop(grayImage, props.BoundingBox); % Crop to outermost bounding box of the good pixels.
If the regions are interior and irregularly shaped you could use isnan to get a map of where they are and use regionfill to fill them in by smearing surrounding values into the region,
badPixels = isnan(grayImage);
grayImage = regionfill(grayImage, badPixels);
or you could assign some non-nan gray level, like 0, to them.
badPixels = isnan(grayImage); % Mask of where the NaNs are
grayImage(badPixels) = 0; % Make nans zero
  1 件のコメント
Don Max
Don Max 2022 年 6 月 29 日
編集済み: Don Max 2022 年 6 月 29 日
Hi @Image Analyst,@DGM, I think you didn't get my question. I will explain detail
From the picture, you can see rectangular shape with fringes (This is my measurement object). I want to reconstruct this shape using triangulation. For that, I want to make all the unwanted regions (regions other than measurement object) to NaN.
The image which i uploaded have no any NaN values.
Attaching wn edited image here, from this you clearly get whis is unwanted region!

サインインしてコメントする。

その他の回答 (1 件)

DGM
DGM 2022 年 6 月 29 日
編集済み: DGM 2022 年 6 月 29 日
IPT regionfill() can do inpainting based on a logical mask. You could use isnan() to derive the mask from the image.
Alternatively, you could use John's inpaint_nans() from the FEX. That should be able to work directly on the image, inpainting NaN regions without extracting a mask.
If your image is monochrome, and you want to fill those regions with a solid black/white/gray fill, you can do
mk = isnan(myimage); % create mask from image
myimage(mk) = 0.6; % fill nan regions with 60% gray

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by