Using output of the fit function in further calculations
11 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to correct for the change in intensity of an image due to the lighting position. I thought that if I found the polynomial of a fitted surface I could use that to correct the image. I have used the fit function to fit a surface and have managed to generate a polynomial along with the variable values. My problem is that I can't figure out how to calculate val(x,y) for each pixel in the image using the generated polynomial and variables (which I then plan to subtract from my original image). How can I get the formula and variables back into usable code, please?
Many thanks.
Here is the code that I have been using:
backGround = im2double(imread('E3W.JPG'));
subset = backGround(1:50:3000,1:50:4096);
B = reshape(subset,[],1);
si = size(subset);
[x,y] = ndgrid(1:si(2),1:si(1));
x = reshape(x,[],1);
y = reshape(y,[],1);
sf = fit([x, y],B,'poly33');
coefficientNames = coeffnames(sf);
coefficientValues = coeffvalues(sf);
curve = formula(sf);
curve_string = convertCharsToStrings(curve);
curve_symbol = str2sym(curve_string);
curve_usable = str2func(curve_string);
0 个评论
采纳的回答
Steven Lord
2023-11-27
If all you want to do is evaluate the surface fit there's no need to break it into its components parts and re-assemble it. I'll show an example with a curve fit, but the principle is the same for surfaces.
load census
% Create fit using data from census.mat
F = fit(cdate, pop, 'poly2', 'Normalize', 'on')
% Evaluate fit for year 1955
p1955 = F(1955)
% Plot original data, fit, and point for year 1955
plot(F);
hold on
plot(cdate, pop, 'ko', 1955, p1955, 'bx')
I'd say that fitted curve fits the data reasonably well and that the evaluated point is on the fitted curve.
更多回答(1 个)
Mathieu NOE
2023-11-27
hello
why not use the smoothed (low pass filtered) image as a new background and you remove that from the original image. In fact this is the same as applying a 2D high pass filter
for the smoothed image I used smoothn available here : smoothn - File Exchange - MATLAB Central (mathworks.com)
you can change the amount of smoothing if you want
backGround = im2double(imread('E3W.JPG'));
backGround2 = smoothn(backGround);
backGround3 = backGround- backGround2;
figure(1),
subplot(1,3,1),imagesc(backGround);
subplot(1,3,2),imagesc(backGround2);
subplot(1,3,3),imagesc(backGround3);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!