为什么修复失败以及如何修复?
我有一个 100x100 numpy 数组,大约是 47% nan。我想修复 nan 较小的连接区域。这是输入数组,nans 是白色的。
以下是 nan(白色):
m_nans = np.isnan(input).astype(np.uint8)
这里我选择面积低于任意阈值的 nans 的连接区域:
n,nans_labelled,stats,centroids = cv2.connectedComponentsWithStats(m_nans)
labels = np.where(stats[1:, 4] < 500)[0] + 1
m_nans_small = np.isin(nans_labelled, labels).astype(np.uint8)
现在我想要修复上面的区域,我们从半径 3 开始。
inpainted = cv2.inpaint(input, m_nans_small, 3, cv2.INPAINT_NS)
这些是修复区域:
然后我尝试将半径增加到 10,结果没有任何结果修复了。然后我尝试扩大面具,这导致南被修复。考虑到较高的半径只会导致 nan 被修复,我再次尝试将所有 nan 屏蔽(m_nans
)。对于我真正感兴趣的修复区域 m_nans_small
,结果是相同的。然后我尝试使用 m_nans_small 尝试尽可能小的半径 (1),虽然这会修复更多区域,但它无法完全修复感兴趣的区域。与我想要修复的区域的面积相比,半径 1 也太小了。
有趣的是,如果我尝试递归修复 - 修复上面用与原始蒙版相交的图像中的 nan 蒙版的图像 - 没有明显的改进,即使使用最小半径。这表明修补不会因为缺少油漆而失败。即使完全被有效像素包围的两个像素区域也无法修复。
m_nans_small_remaining = np.isnan(inpainted) & m_nans_small
inpainted2 = cv2.inpaint(inpainted, m_nans_small_remaining, 1, cv2.INPAINT_NS)
最后我尝试修复扩张的 m_nans
。半径为 1 时,它几乎可以修复任何内容,但由于半径较小,结果很差,并且会覆盖良好的数据。它的半径为 50,用 nan 修复所有内容。
我知道修复失败的原因,但我想确切地知道。然后我想知道如何解决它。
I have a 100x100 numpy array which is about 47% nans. I would like to inpaint the smaller connected regions of nan. Here is the input array, nans are white.
Here are the nans (white):
m_nans = np.isnan(input).astype(np.uint8)
Here I select connected regions of nans with areas below an arbitrary threshold:
n,nans_labelled,stats,centroids = cv2.connectedComponentsWithStats(m_nans)
labels = np.where(stats[1:, 4] < 500)[0] + 1
m_nans_small = np.isin(nans_labelled, labels).astype(np.uint8)
Now I would like to inpaint the regions above, lets start with radius 3.
inpainted = cv2.inpaint(input, m_nans_small, 3, cv2.INPAINT_NS)
And these are the inpainted regions:
Then I tried increasing the radius to 10 which resulted in nothing being inpainted. Then I tried dilating the mask, which led to nans being inpainted. Thinking higher radius caused only nans to be inpainted, I tried again with all nans masked (m_nans
). The result was identical for the regions I was actually interested in inpainting, m_nans_small
. Then I tried the smallest radius possible (1) with m_nans_small
and while that inpaints more regions, it fails to fully inpaint the region of interest. A radius of 1 is also too small compared to the area of the regions I want to inpaint.
Interestingly, if I try to inpaint recursively - inpaint the image above masked with the nans from that image intersected with the original mask - there is no noticeable improvement, even with the smallest radius. This suggests that inpainting does not fail from a lack of paint. Even two-pixel regions completely surrounded by valid pixels fail to inpaint.
m_nans_small_remaining = np.isnan(inpainted) & m_nans_small
inpainted2 = cv2.inpaint(inpainted, m_nans_small_remaining, 1, cv2.INPAINT_NS)
At last I tried inpainting a dilated m_nans
. With a radius of 1 it inpaints almost anything, but the result is shoddy due to the small radius, and it overwrites good data. With a radius of 50 it inpaints everything with nans.
I have some idea why inpainting fails, but I would like to know for sure. Then I would like to know how to fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论