MATLAB: Calculate the cone angle of a spray image

angle calculationcone angleimage processpray angle

Hi Guys,
I am trying to write a code to measure the cone angle of some spray images. I have attached the original image '2006.jpg', that's what I have to start with. I also attached how a possible final picture could look like '2006i.jpg'. Note: I don't need the final image, I am just interested in the correct angle.
I know there are different approaches how to calculate the angle since the spray varies in thickness. Basically, I am happy for any method as long as the method is consistent to compare my angle between different liquids.
Here's what I have tried so far: I cropped the picture to the edges of the window and converted the coloured image into black&white. Whit the edge-function using the Sobel-filter I got the contours of the spray
_ clear, clc, close all
Image = imread(['2006.jpg']);
[a1 a2 a3]=size(Image);
x0=215; %if picture higher than increase number 215
y0=255; %if picture to the left than increase number 255
r=170; %170
for i=1:a1
for j=1:a2
if (i-x0)^2+(j-y0)^2>=r^2
Image(i,j,:)=255;
end
end
end
Image2=imadjust(rgb2gray(Image));
figure(1); imshow(Image2)
hold on
BW = im2bw(Image2);
figure(2); imshow(BW)
BW1 = edge(BW,'sobel');
figure(3); imshow(BW1);
size(BW1)_
Here an idea of how my solution could look like:
I guess my next step would be to scan through the picture to find the pixel, which form the spray contours using the find() command and then plot to lines to represent the interpolation of the spray edges using the "interp() command(?). With the intersection of the two lines the angle can be calculated. Sounds easy, but I don't know how that could look like.
Any ideas? Many thanks in advance!

Best Answer

Personally, I'd use a different approach. You almost never want to use edge detection when thresholding is fine, which is your situation. ALso it looks like your have a fixed field of view so you could have a fixed mask to mask out the black surround and nozzle (otherwise use imclose, thresholding, imclearborder, etc.). So now you have an image of just the spray. Then I'd threshold and call regionprops to get the angle (orientation) of the spray. Then I'd march along that axis taking cross sections of the spray perpendicular to the main axis and calculate the angle. So you'd have an angle for every point along the spray axis. Then you have to examine that curve to see which of those angles is the one you want to use to characterize the spray. For example, maybe the angle approaches a constant value after a certain distance, or maybe it decreases (if the spray turns into a parallel column) and you want to use the peak angle, or peak angle once it has gone further than a certain distance.