Effacer les filtres
Effacer les filtres

Degrade image with known MTF to another desired MTF

21 vues (au cours des 30 derniers jours)
Eric
Eric le 20 Juin 2024
Commenté : Eric le 21 Juin 2024
Hi folks,
I want to be able to degrade an image captured by a camera system with known MTF to another hypothetical desired MTF. I thought I would start by blurring an image with a gaussian PSF and try and extract its MTF from the final image.
MTF_output = MTF_input*MTF_blur
Right now, MTF_output and MTF_input can be calculated from the slanted edge image I have. Eventually, I will generate MTF_blur from the desired MTF_output I want. This to prove the math works out.
I calculate MTF_blur two ways.
1) The ratio MTF_output./MTF_input.
2) Extracted from the PSF used to blur the image.
The problem is both methods don't match.
I think I may be missing something regarding scaling to my optical system or perhaps frequency units. I have no specific camera parameters in this code, although the system is ~3 pixels per degree.
Thanks in advance!
% Read in image and convert to mono double.
img = imread('img_input.png');
img = double(rgb2gray(img));
% Crop to edge and perform slanted edge MTF calc
rect = [308.51 198.51 62.98 51.98];
img_cropped = imcrop(img,rect);
[~, data,~, ~, ~, ~, ~] = sfrmat3(1, 1, [], img_cropped);
freq = data(:,1);
mtf_input = data(:,2);
% Generate PSF used to degrade the image
PSF = fspecial('gaussian',13,1);
% Convert the PSF to an Optical Transfer Function (OTF).
OTF = psf2otf(PSF,[31 31]);
% Extract the MTF from OTF:
MTF_blur_fromPSF = diag(OTF); % Should be circular symmetric, but OTF is a square matrix.
% Blur Image
img_blurred = conv2(img,PSF,'same'); % apply convolution to entire image to avoid edge artifacts
% Crop to edge and perform slanted edge MTF calc
img_blurred_crop = imcrop(img_blurred,rect);
[~, data,~, ~, ~, ~, ~] = sfrmat3(1, 1, [], img_blurred_crop);
freq_output = data(:,1);
mtf_output = data(:,2);
plot(freq, mtf_input); hold on; plot(freq_output, mtf_output);
MTF_blur_fromRatio = mtf_output./mtf_input;
plot(freq,MTF_blur_fromRatio)
axis([0 0.5 0 1])
plot(linspace(0,1,length(MTF_blur_fromPSF)),MTF_blur_fromPSF) % assuming MTF_blur_fromPSF is 0-1 1/pixel units
xlabel('Frequency [cy/px]')
ylabel('MTF Response')
legend('Original MTF','Blurred MTF','MTF_blur_fromRatio','MTF_blur_fromPSF','Interpreter', 'none')

Réponse acceptée

Matt J
Matt J le 20 Juin 2024
Modifié(e) : Matt J le 20 Juin 2024
sfrmat3 is 3rd party code, so nobody here knows what it is doing. I suspect at least part of the problem is that img_blurred is generated with a rather undersampled Gaussian PSF (sigma=1 pixel). I would only expect two independent MTF estimation methods to agree for a well-sampled PSF.
Regardless, we know what the theoretically predicted MTF is supposed to be and the revised code below seems to give it correctly, or at least it gives the correct HWHM=2.355/(4*pi).
% Generate PSF used to degrade the image
PSF = fspecial('gaussian',101,1);
% Convert the PSF to an Optical Transfer Function (OTF).
OTF = psf2otf(PSF,101*[1 1]);
MTF_blur_fromPSF = OTF(:,1);
N=height(OTF);
fAxis=(0:N-1)/N;
plot(fAxis,MTF_blur_fromPSF);
axis([0 0.5 0 1])
xline(2.355/(4*pi),'--'); yline(0.5,'--') %The predicted HWHM
xlabel('Frequency [cy/px]')
ylabel('MTF Response')
  3 commentaires
Matt J
Matt J le 20 Juin 2024
Thanks for the answer Matt!
You are quite welcome, but please Accept-click the answer to indicate that it resolved your issue.
I'm curious what sources of error could be leading to the (much smaller) descrepancy I am seeing now.
As I mentioned, you are simulating img_blurred with a somewhat undersampled PSF. Did you try with a larger sigma?
Eric
Eric le 21 Juin 2024
Sigma set to 2 (PSF = fspecial('gaussian',101,2);) yields good alignment. I'll be sure the PSFs I apply in the future are properly sampled. Thanks again!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by