Linear regression-line based on 2D image

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.
test1.jpg
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

4 commentaires

Image Analyst
Image Analyst le 6 Déc 2018
I don't think contourf() is the right approach. Can you upload the original image by itself. The good PNG or TIFF image, not the crummy JPG image with crummy jpg artifacts. Don't use jpg format for image analysis if you can at all help it. Also post a picture of what you consider to be the edge. Like, is that junk at the top noise to be ignored, or a legimate edge? Also, is the shape standard, so that you could correlate a standard template with it using normxcorr2(), or is the shape different from image to image?
Okay. So the original Image is actually a .jpg. The microscopesoftware used to take the image always saves in high resolution jpg accompanied by a meta xml file. Anyway, the samples will never be quite the same. I'm trying to determine how colse the two edges (left and right) are to being parrallel, while also determining the curvature of the top of the sample (yellow layer on original image - then one I just uploaded), by fitting the periferi of a circle to match the layer and then determine the radius of that circle.
And since the images are taken with a microscope, the location of the samples are never going to be the same. They have to be analysed individually. Anyway, I'll look into what you suggested and return if I reach a solution (or if I recieve more suggestions J).
And yes, the stuff at the top has to be ignored. It should be clear to see the edge I'm talking about on the high res image (the edge starts at the bottom, being a lighter gray than the rest).
I'm sorry for not keeping this reply in a single comment, but my computer is having a very hard time after I uploaded the image on this page.

Connectez-vous pour commenter.

Réponses (0)

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by