2
votes

I want to reconstruct missing values in a floating point matrix in OpenCV. The Mat contains floating values with minimum value 0. I tried this :

  1. Convert floating point Mat to CV_8U . The CV_8U image when displayed (points with 0 in floating Mat appear as black):

    floating Mat to image

  2. Generate a mask by checking 4-neighborhood for atleast one non zero pixel with current pixel being zero. Mask depicts pixels to be reconstructed(255-missing pixels and 0-otherwise) The mask is :

mask

  1. Used inpaint function with image obtained in step 1 and mask from step 2. The inpainted result :

inpainted result

Now I have pixel values at missing locations(above image) but this inpaint cannot be directly applied to floating point Mat. It accepts only 8-bit 1-channel or 3-channel image. How can I reconstruct/obtain missing values in the floating point Mat ?

1

1 Answers

0
votes

If losing precision from the float-uchar conversion is acceptable across the entire image, you can do:

cv::Mat result;
inpainted_image.convertTo(result, CV_32F);

If you only want to fill in the missing values, do the above and then transfer the result values where your mask is nonzero.