필터 지우기
필터 지우기

how to inpaint a region of interest recursively

조회 수: 9 (최근 30일)
David Levi
David Levi 2022년 1월 28일
댓글: Image Analyst 2022년 1월 28일
Hi everyone!
I have an image called 'lion.jpg' .
I did segmentation to the lions in the center using the segmentImage.m function , and got this image:
I need to inpaint the black region that was created , and I need a solution to do that recursively from outside to inside:
I tried to use the inpaintCoherent function but the result was not acually what i needed , I got this:
You can see that the inpaintCoherent function filled the area of the mountains with colored lines , and this is not good for me. I want to fille the region smoothly.
I tried to blure the region but I really dont want to do that.
I shared my code : try1.m with you, and you can see it here too:
clc;
clear;
close all;
I = imread('lion.jpg');
figure; imshow(I,[]);
[BW,mask] = segmentImage(I);
figure; imshow(BW);
bg = I - mask;
figure; imshow(bg)
figure; montage({I,BW});
%% inpaint
title(['Image to Be Inpainted',' | ','Mask for Inpainting']);
J = inpaintCoherent(I,BW,'Radius',7);
figure; imshow(J);
figure;
montage({I,J});
title(['Image to Be Inpainted',' | ','Inpainted Image']);
%% try to blur the image:
redChannel = J(:, :, 1);
greenChannel = J(:, :, 2);
blueChannel = J(:, :, 3);
% H = fspecial('disk',20);
H = fspecial('average',33);
redChannel = roifilt2(H,redChannel,BW);
greenChannel = roifilt2(H,greenChannel,BW);
blueChannel = roifilt2(H,blueChannel,BW);
rgbImage = cat(3, redChannel,greenChannel,blueChannel);
figure;
subplot(1,2,1); imshow(J); title('Inpainted Image');
subplot(1,2,2); imshow(rgbImage); title('image after blure');

채택된 답변

Image Analyst
Image Analyst 2022년 1월 28일
The function you want is called regionfill().
Description
J = regionfill(I,mask) fills the regions in image I specified by mask. Non-zero pixels in mask designate the pixels of image I to fill. You can use regionfill to remove objects in an image or to replace invalid pixel values using their neighbors.
J = regionfill(I,x,y) fills the region in image I corresponding to the polygon with vertices specified by x and y.
  댓글 수: 2
David Levi
David Levi 2022년 1월 28일
편집: David Levi 2022년 1월 28일
First of all, thank you for your answer!
I have another one for you.
Here is the result of the regionfill function:
now I have another idea.
Is it possible to create a roi (rectangle) of the mountains near the segmented area , and replace with it the restored area? :
The motivation is to create something like this (I used Microsoft Paint....)
do you have any idea how to do it in matlab interactively?
Image Analyst
Image Analyst 2022년 1월 28일
Terrain generation is not trivial. You can try image quilting:
Or you can try to generate something using Perlin noise (Google it).
Or you can just get rid of the columns with "seam carving" (Google it).
Since it looks like a one-off situation, maybe you can just interactively clone part of the image using the Clone Stamp tool in Photoshop.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by