Degrade image with known MTF to another desired MTF
조회 수: 24 (최근 30일)
이전 댓글 표시
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1719476/image.jpeg)
% 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')
댓글 수: 0
채택된 답변
Matt J
2024년 6월 20일
편집: Matt J
2024년 6월 20일
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
Matt J
2024년 6월 20일
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?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!