讓我們有一個損壞的圖像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
'A = C/B;'未'登錄A =日誌C /登錄B' –
是它不是。這就是爲什麼我做f = cImage - modeledColorChannel執行步驟日誌A =日誌C - 日誌乙和這是我的問題,爲什麼我得到較小的RMSE而不是減法。讓我知道如果我弄錯了。 @AnderBiguri –