Is Pixel Interpolation possible in MATLAB? If so, how?

조회 수: 13 (최근 30일)
Ali Almakhmari
Ali Almakhmari 2022년 7월 30일
답변: Image Analyst 2022년 7월 31일
Hey guys. So I have a picture, but unfortunately, some pixels in it are completely black (the RGB values are 0,0,0). For those specific pixels, I would like to do some sort of pixel interpolation (replace those black pixels by a pixel that is interpolated from the surrounding area). I tried doing it myself but I struggled with multiple things, one of them is how to tell MATLAB what are the pixels that I want to replace and what are the pixels that I want it to interpolate from. Any ideas?

채택된 답변

DGM
DGM 2022년 7월 30일
You should be able to use regionfill()
% a test array with a zero pixel
A = uint8(randi([0 255],5,5));
A(3,3) = 0;
imshow(A)
% create a mask that describes the zeros
mk = A == 0;
% inpaint
B = regionfill(A,mk);
imshow(B)
  댓글 수: 2
Ali Almakhmari
Ali Almakhmari 2022년 7월 30일
I tried implementing this on my image but its hardly working cause its a colored image. I tried comverting it to gray and work on it, which it did, but converting it back to colored after using regionfill is very diffcuilt. Any suggestions?
Image Analyst
Image Analyst 2022년 7월 31일
Maybe regionfill try it on each channel one at a time
% Split RGB image apart into separate color channels.
[r,g,b] = imsplit(rgbImage);
% Fill holes in each channel individually.
r = regionfill(r, mask);
g = regionfill(g, mask);
b = regionfill(b, mask);
% Recombine
rgbImage = cat(3, r, g, b);
There are other ways (some are perhaps more "accurate"), but this might be the simplest and be good enough.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 7월 31일
You might take a look at inpaintCoherent or inpaintExemplar.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by