Linear regression-line based on 2D image
6 次查看(过去 30 天)
显示 更早的评论
Hi there,
I'm currently trying to determine the edge of an image of a sample I'm working with. The image on the left is the actual sample (heavily cropped). I made a contourf plot to better be able to see the actual edge I need to create the regression line for (yellow edge on image to the right).
Does MATLAB have a feature that can do this? I have been messing around with gradient and edge, but without luck.
A little info on the original image (the axis are in pxl btw):
I import the image from a .jpg file using the imread function. I then split up the image in to two coordinate matrices (X, Y) and three matrices containing the R G B information. Something like this:
[X,map] = imread(fullfile(filepath, strcat(name, ext)));
X = ind2rgb(X,map);
dim = size(X);
y = linspace(0,dim(1)-1,dim(1));
x = linspace(0,dim(2)-1,dim(2));
[img.X,img.Y] = meshgrid(x,y);
img.R = I(:,:,1);
img.G = I(:,:,2);
img.B = I(:,:,3);
To do the contourf plot I have to make some small changes, they look like this:
R = double(img.R);
G = double(img.G);
B = double(img.B);
z = (R.*G.*B).^(1/3); % Not really sure if this is the best way to represent RGB by single number, but it gives an acceptable contourf plot
contourf(img.X,img.Y,z,2)
So I basically have a matrix (z) which contains all the information I need. I'm just not sure how to handle it.
Any advice is welcome.
Thanks in advance.
Best regards,
Jesper
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!