0

让我们有一个损坏的图像C,偏置轮廓,B和真实图像A.所以,如果我们可以定义一个模型,为什么表面拟合在对数域中不起作用?

C = A * B;

我们可以得到原来的图像返回如,

A = C/B;

在对数域中

日志A =日志Ç - 登录B.

现在让我们说,我有真正的形象,和我介绍偏差B和我收到损坏的图像C.现在我可以使用多项式回归来纠正这个有偏见的图像C。如果我在日志域中转换损坏的图像C,我将适合该表面,并且如上所示,我可以从中减去偏移配置文件。减法后,我不需要应用exp(log C - log B)。 Onlu标准化需要获得[0 255]范围。

算法:没有任何偏置场

  • 原始图像被引入与多项式曲线,这导致具有非均匀照明的图像。

  • 偏图像被转换在日志结构域和表面使用多项式拟合

  • 近似表面由这导致原始图像后面没有偏磁场的偏图像中减去近似。(理想情况下)。

  • 在步骤1中测量近似表面和引入的多项式场之间的RMSE。测量偏压图像和减法后最后得到的图像之间的RMSE。

代码:

clear;clc;close all; 

%read the image, on which profile is to be generated 
I = ones(300); 
I = padarray(I,[20,20],'both','symmetric'); % padding 

%% 
%creating a bias profile using polynomial modeling 
[x,y] = meshgrid(1:size(I,1),1:size(I,2)); 
profile = -2.5.*x.^3 - 2.5.* y.^3 + 0.25 .*(x.* y.^2) - 0.3*(x.^2 .* y) - 0.5.* x .* y - x + y - 2.5*(x.^2) - y.^2 + 0.5 .* x .*y + 1; 

% come to scale [0 1] 
profile = profile - min(profile(:)); 
profile = profile/max(profile(:)); 
figure,imshow(profile,[]); %introduced bias profile 


%% corrupt the image 
biasedImage = (I .* profile); 
figure,imshow(biasedImage,[]); %biased Image 


cImage = log(biasedImage+1);% conversion to log domain/ +1 is needed to avoid infinite values in case of 0 intensty values in corrupted image. 

%% forming the input for prediction of surface 
colorChannel = cImage; 
rows = size(colorChannel, 1); 
columns = size(colorChannel, 2); 
[X,Y] = meshgrid(1:columns, 1:rows); 
z = colorChannel; 
x1d = reshape(X, numel(X), 1); 
y1d = reshape(Y, numel(Y), 1); 
z1d = double(reshape(z, numel(z), 1)); %dependent variables 
x = [x1d y1d]; % two regressors 

%% surface fitting 
m = 3; %define the order of polynomial 
p = polyfitn(x,z1d,m); %prediction step 
zg = polyvaln(p, x); 

modeledColorChannel = reshape(zg, [rows columns]); % predicted surface 

%modeledColorChannel = exp(modeledColorChannel)-1; if we use this step then  the step below will be division instead of subtraction 
%f = biasedImage./ modeledColorChannel; Same as the step below but as we are using exponential, it will be devision. 

%% correction 
f = cImage- modeledColorChannel; %getting the original image back. 


%grayImage = f(21:end-20,21:end-20); 
%modeledColorChannel = modeledColorChannel(21:end-20,21:end-20); %to remove the padding 

figure,imshow(f,[]); 
figure,imshow(modeledColorChannel,[]); 


%% measure the RMSE for image 
y = (I - f); 
RMSE = sqrt(mean(y(:).^2)); 
disp(RMSE); 

% RMSE for profile 
z = (modeledColorChannel - profile); 
RMSE = sqrt(mean(z(:).^2)); 
disp(RMSE); 

结果:

在的情况下:F = cImage- modeledColorChannel

1.0000

0.2127

校正图像: enter image description here

在除法的情况下:F =的CImage ./ modeledColorChannel(尽管它不是按理论是正确的。)

0.0190

0.2127

校正图像:enter image description here

现在,问题是:如果我在日志域中进行分割而不是减法,我在最后得到的RMSE值更低(请参阅%%校正部分)。在理论上正确的情况下,如何有可能获得更高的RMSE减法?根据我的理解,如果我将所有的计算都保留在对数域中,图像分割就会变成图像相减。很明显,如果您运行代码并在对数域中的除法和减法结束时看到图像f。

注:在这两种情况下,作为RMSE我做我的日志域估计在两个cases.Either图像分割或图像减法的介绍和感知配置文件之间是相同的。

请参阅polyfitn工具箱。 www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn

+0

'A = C/B;'未'登录A =日志C /登录B' –

+0

是它不是。这就是为什么我做f = cImage - modeledColorChannel执行步骤日志A =日志C - 日志乙和这是我的问题,为什么我得到较小的RMSE而不是减法。让我知道如果我弄错了。 @AnderBiguri –

回答

0

让我加上我的问题的答案,因为我发现我的错误,以防将来任何人面临同样的问题。

错误1:减法之后,我不需要申请EXP(日志ç - 日志B)那样明显。只需要标准化即可获得[0 255]范围。

我的直觉是,我不需要申请EXP()来获得原始值回。但实际上我必须应用exp()。日志记录LHS和RHS从不相互取消。

如果日志(A)=日志(B),得到了一回值我需要A = EXP(日志(B))。

错误2:在数域,我减去两个图像,所以我没有去面对无穷的问题在对数域中,我们通常面临分裂的情况。

所以,简单而数域转换形象,我可能只是这样做,

cImage = log(biasedImage); 

代替,

cImage = log(biasedImage+1); 

这里,添加+1创造在影像中不需要的模糊,因为在估计,同时预测表面会在黑暗区域将表面推向高值。

相关问题