图像修复序列——FFM模型

该博客详细介绍了FFM(Field-aware Factorization Machine)模型在图像修复领域的实现过程,包括模型代码的编写和模型的运行效果展示,是理解FFM模型在图像修复技术上应用的良好参考资料。

1. 参考文献



2. FFM模型实现

2.1 FFM模型代码

%%%%%%%%%%%%%%%%%%%%%%%%%%% Demo of Fast March Method %%%%%%%%%%%%%%%%%%%%%
% Date: 2014-10-23
% author: HSW
% HARBIN INSTITUTE OF TECHNOLOGY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
clear all
clc;

% 读入图像
BAND = 1;
KNOWN = 2;
INSIDE = 3;
% 读入图像
I = imread('C10.bmp');
M = imread('mask2.png');
% 彩色图像
if size(M,3) == 3 
    M = rgb2gray(M);
    M = M>0;
end
figure; 
imshow(I, []); 
title('原图像'); 

I = im2double(I);
Temp(:,:,1) =  M;
Temp(:,:,2) =  M;
Temp(:,:,3) =  M;
I = (1-Temp).*I;  %+ Temp.*0.5;
% % 灰度图像
% if ndims(M)
%     M = rgb2gray(M);
%     I = rgb2gray(I);
% end
% M = M<1;
% I = double(I);
% Temp = M;
% I = (1-Temp).*I + Temp.*255;
figure;
imshow(I,[]);
title('原图像');
% 标记
[m,n,dims] = size(I);
M1 = (bwdist(M,'cityblock') <= 1);
%初始化flag值
flag = INSIDE*M + KNOWN*(1-M);
flag =(1-M1+M).*flag+BAND*(M1-M);
%初始化 T
T = zeros([m,n]) + 1e6.*M;
IterMax = 10;
for iter = 1:IterMax
    [I] = fast_march_method(I,T,flag);
end

figure;
imshow(I,[]);
title('修复结果');

2.2 FFM模型

function  [I,T,flag] = fast_march_method(I,T,flag)
% input:
%      I: 待修复图像
%      M: 缺损区域mask,缺损区域 = 1
%      T: 距离标记矩阵
%      flag:标记矩阵,BAND/KNOWN/INSIDE
% output:
%       I: 修复图像
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BAND = 1;
KNOWN = 2;
% INSIDE = 3;
[m,n,dims] = size(I);
iter = 0;
while find(flag == BAND)  %存在待修复点
    % 获取T最小的点的坐标
    xposition = 1;
    yposition = 1;
    Tmin = 1e6;
    for i = 1:m
        for j = 1:n
            if (flag(i,j) == BAND) && (T(i,j) < Tmin )
                xposition = i;
                yposition = j;
                Tmin = T(i,j);
            end
        end
    end
  
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值