MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# help with edge processing in an image.

Asked by mounim on 19 Dec 2012

HeY everyone

i hope someone can help me with a project, what i am trying to do is calculating the angle between 2 bones. I already got some help with drawing the axis of the bones from this forum. but as you can see, in the the bottom part i have 2 bones, what can do to only get the axis through the thicker bone ( i only want to define the edge of the thicker bone )? anyhelp will be appreciated, thanks

```clc;
close all;
imtool close all;
clear;
fontSize = 20;
```
```grayImage = imread('6.jpg');
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage)
% Convert to grayscale
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2);
end
% Crop away white boundary
%grayImage = grayImage(1:840, 1:450);
% Binarize the image
binaryImage = grayImage > 128;
% Display the original gray scale image.
% subplot(2, 2, 1);
imshow(grayImage, []);
```
```% for loop to define the range of interest for the bone 1
for k=30:100
```
`     oneRow = binaryImage(k, :);`
```     leftEdge = find(oneRow, 1, 'first');
rightEdge = find(oneRow, 1, 'last');```
`     hold on;`
`     midpoints(k) = (leftEdge + rightEdge)/2;`
```     plot(leftEdge, k, 'rx','LineWidth',2);
plot(rightEdge, k, 'rx','LineWidth',2)```
`     plot(midpoints(k), k, 'yx','LineWidth',2);`
```end
```
```X=(30:100);
midpoints=midpoints(midpoints~=0);
new_x = linspace(1, 400);
coeffs = polyfit(X, midpoints, 1);
new_y = polyval(coeffs, new_x);
plot(new_y,new_x, '-','LineWidth',2);
```
```% for loop to define the range of interest for the bone 1
for i=700:800
```
`     oneRow1 = binaryImage(i, :);`
```     leftEdge1 = find(oneRow1, 1, 'first');
rightEdge1 = find(oneRow1, 1, 'last');```
`     hold on;`
```if isempty(leftEdge1)
midpoint1(i) = 0;
else
midpoints1(i) = (leftEdge1 + rightEdge1)/2;
```
```     plot(leftEdge1, i, 'rx','LineWidth',2);
plot(rightEdge1, i, 'rx','LineWidth',2);```
```     plot(midpoints1(i), i, 'yx','LineWidth',2);
end
end```
```X1=(700:800);
midpoints1=midpoints1(midpoints1~=0);
new_x1 = linspace(500, 900);
coeffs1 = polyfit(X1, midpoints1, 1);
new_y1 = polyval(coeffs1, new_x1);
plot(new_y1,new_x1, '-','LineWidth',2);
```
```Femur = abs(atand(coeffs(1)));
Tibia = abs(atand(coeffs1(1)));
```
```Angle = Femur + Tibia;
```
```title(Angle , 'FontSize', fontSize);
```

## Products

Answer by mounim on 20 Dec 2012