Degrade image with known MTF to another desired MTF
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’)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’) 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’) image analysis, simulation, mtf, psf, image processing MATLAB Answers — New Questions