How does imflatfield work?

14 ビュー (過去 30 日間)
Julia Kelly
Julia Kelly 2019 年 11 月 12 日
コメント済み: Arthur Redgate 2023 年 9 月 1 日
What formula does the imflatfield function use when used with a matrix as input?
For example, I have an image of surface temperature (attached) = bad_img. If I apply
corr_img = imflatfield(bad_img,100);
How can I reproduce corr_img without using imflatfield? I know that the gaussian filter can be generated using
iblur=imgaussfilt(bad_img, 100);
But what are the next steps?
  1 件のコメント
William Nitsch
William Nitsch 2021 年 10 月 2 日
Iout = Iin * mean(gaussian_blurred_img)/gaussian_blurred_img

サインインしてコメントする。

回答 (1 件)

DGM
DGM 2021 年 10 月 2 日
編集済み: DGM 2021 年 10 月 2 日
William's comment is close. Probably close enough to be useful, but not quite exactly the same as what imflatfield() does.
A = imread('printedtext.png');
sigma = 30;
% this is the reference
output1 = imflatfield(A,sigma);
% this is a replication of the behavior
A = im2single(A); % non-double images are converted to single
% this is the default filter size, but it can be set explicitly too
blurred = imgaussfilt(A,sigma,'padding','symmetric','filtersize',2*ceil(2*sigma)+1);
output2 = A*mean(A(:),'omitnan')./blurred; % mean of A, not of blurred image
output2 = im2uint8(output2);
immse(output1,output2) % show that the results match
ans = 0
Bear in mind that if you want to exactly replicate the behavior, there are other things that happen (e.g. dealing with NaNs and Inf) that need to also be considered. You can always just open imflatfield() and read it.
EDIT: oof. This wouldn't be the first time I absentmindedly answered a dead question...
  1 件のコメント
Arthur Redgate
Arthur Redgate 2023 年 9 月 1 日
I appreciate your answer as it's helped me 5 years after the asking of the original question!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by