Spline smoothing in images
7 views (last 30 days)
Show older comments
Can anyone guide me how we use splines for interpolation in images? I mean how we relate value of x,y of spline function in an image that has its spatial coordinates and intensity values.
Answers (3)
Image Analyst
on 8 Feb 2013
A 2D Savitzky Golay filter is similar, and I already have code for that. Basically it replaces each pixel with a polynomial fit over a sliding window. It gives the effect of smoothing. Let me know if you have the Signal Processing Toolbox and would like my demo.
2 Comments
Image Analyst
on 8 Feb 2013
The sgolay function is not contained in the Image Processing Toolbox. What is does is fit a 25 element 1D vector of gray levels to a polynomial (I used 1 but you can use order 3 if you want) and then it replaced the center value with the value from the fitted curve. It does this column by column (sliding the 25 element window down the rows in each column), and then it does it row by row (blurring across columns) to get a 2D blur.
Try this:
% Filter using Savitzky-Golay filtering.
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Check that user has the Image Processing Toolbox installed.
hasSPT = license('test', 'signal_toolbox');
if ~hasSPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Signal Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in standard MATLAB gray scale demo image.
% imageArray = imread('football.jpg');
imageArray = imread('cameraman.tif');
imageArray = double(imageArray);
[rows columns numberOfColorBands] = size(imageArray);
subplot(2, 2, 1);
imshow(imageArray, [0 255]);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.
set(gcf,'name','Savitzky-Golay Filter Image Analysis Demo','numbertitle','off')
% Apply the Savitzky-Golay filter.
% First apply it in the vertical (row) direction.
k = 1; % Order of the polynomial
windowSize = 25;
verticallySmoothedImage = sgolayfilt(imageArray, k, windowSize, [], 1);
subplot(2, 2, 2);
imshow(verticallySmoothedImage, [0 255]);
title('Savitzky-Golay filtered in the vertical direction only', 'FontSize', fontSize);
% Apply the Savitzky-Golay filter.
% First apply it in the vertical (row) direction.
k = 1; % Order of the polynomial
windowSize = 25;
horizontallySmoothedImage = sgolayfilt(imageArray, k, windowSize, [], 2);
subplot(2, 2, 3);
imshow(horizontallySmoothedImage, [0 255]);
title('Savitzky-Golay filtered in the horizontal direction only', 'FontSize', fontSize);
doublySmoothedImage = sgolayfilt(verticallySmoothedImage, k, windowSize, [], 2);
subplot(2, 2, 4);
imshow(doublySmoothedImage, [0 255]);
title('Savitzky-Golay filtered in both directions', 'FontSize', fontSize);
Mehri Mehrnia
on 7 May 2022
I have the same question. In all spline questins, we map coordinates of points and then interpolate.
But, for imaging, how I can map the matrix arrays and interpolate????
4 Comments
Mehri Mehrnia
on 13 Jun 2022
You mentioned valuable points but I didn't get all of them. what is "Image Analyst posted code for"?
Walter Roberson
on 13 Jun 2022
https://www.mathworks.com/matlabcentral/answers/62692-spline-smoothing-in-images#comment_128156 is the posted code
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!