Hi,
I have to find slope by using curve fitting in this figure. There are 7 wavefronts in this image. What method should I apply? I have tried different techniques like I manually selected 2 points and find slope but that is not appropriate way. I have to utilize all the data points and fit curve to all 7 wavefronts. Sample image is attached here

답변 (2개)

KSSV
KSSV 2022년 2월 16일

1 개 추천

If (x,y) are the points of your curve...
m = gradient(y)./gradient(x) ; % diff(y)./diff(x)

댓글 수: 7

Leostar90
Leostar90 2022년 2월 16일
What is x and y here? First I have to find Data points of the wavefront and then I have to fit curve.
KSSV
KSSV 2022년 2월 16일
In the plot you have a legend, fitted curve. What's that?
Leostar90
Leostar90 2022년 2월 16일
In first picture, I selected three points manualy. Then using mathematical manipulations I found constants of quadratic equations and then I used "fit" function with "poly2" and then green line was plotted on the wavefront. But in this way I only used 3 points manually. What I want to do is to find many data points or all points of wavefront and then fit a best fitting curve utilizing all data points. Moreover, there are 7 wavefronts and have to do same for all.
KSSV
KSSV 2022년 2월 16일
Wavefront has 2D data right? On this use polyfit. Read about polyfit.
Leostar90
Leostar90 2022년 2월 16일
these are pixel values. I read about polyfit but that need x and y.
KSSV
KSSV 2022년 2월 16일
Yes, for the pixel values the positions are (x,y). You need to seek those positions and fit a curve.
Leostar90
Leostar90 2022년 2월 16일
Yes, I am still there.. How to find those positions? m = gradient(y)./gradient(x) ; will this work? if I pass x and y positions? Size of data is 50*1024 double. so If I pass x 1:1024 and y 1:50, that Way I can find gradient of every position.

댓글을 달려면 로그인하십시오.

yanqi liu
yanqi liu 2022년 2월 16일

0 개 추천

yes,sir,may be choose the target line by color and fit them,such as
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/896015/image.png');
jm = rgb2hsv(im);
v = mat2gray(jm(:,:,3));
bw = ~im2bw(v,0.9);
bw2 = imopen(bw, strel('line', 20, 0));
bw3 = logical(bw-bw2);
bw3 = imopen(imclose(bw3, strel('disk', 5)), strel('square', 3));
bw3 = bwareafilt(bw3, 2);
[r,c] = find(bw3);
p = polyfit(c,r,3);
xc = linspace(min(c),max(c));
yc = polyval(p,xc);
figure; imshow(im)
hold on; plot(xc,yc,'r--','LineWidth',2);

댓글 수: 2

Hi, Thank you for your response.
When I try to run this code then I get this error.
" Error using rgb2hsv>parseInputs (line 95)
MAP must be a Mx3 array.
Error in rgb2hsv (line 36)
[r, g, b, isColorMap, isEmptyInput, isThreeChannel] = parseInputs(varargin{:});
Error in region_seg_demo (line 18)
jm = rgb2hsv(im);
I have data in mat file. So I am just loading mat file and and after accessing value from mat file just passing it to your above mentioned code.
Here is the code too.
clear all,clc
dta = load('C:\Users\Awais\Downloads\Imgaes\Imgaes\region_seg\image.mat');
im=dta.L;
jm = rgb2hsv(im);
v = mat2gray(jm(:,:,3));
bw = ~im2bw(v,0.9);
bw2 = imopen(bw, strel('line', 20, 0));
bw3 = logical(bw-bw2);
bw3 = imopen(imclose(bw3, strel('disk', 5)), strel('square', 3));
bw3 = bwareafilt(bw3, 2);
[r,c] = find(bw3);
p = polyfit(c,r,3);
xc = linspace(min(c),max(c));
yc = polyval(p,xc);
figure; imshow(im)
hold on; plot(xc,yc,'r--','LineWidth',2);
Leostar90
Leostar90 2022년 2월 17일
did you detect that green line in image or just detected data of that line? I have to apply same curve fitting for all wavefronts in same image? Moreover, I have to find equation of fitted line for finding slope.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 2월 16일

댓글:

2022년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by