MATLAB: How to find the inclination of the back bone in the attached image

Image Processing Toolboximage rotationradon transform

Hello Everyone… Greetings…
I am working with some medical imaging problems.
I want to rotate the given image after finding the inclination angle,
So that backbone looks straight and performs further steps.
I have attached the image for the reference.
The image is high resolution with low quality.
Can anyone suggest, how to find the inclination of the backbone?
Thank you.

Best Answer

  • Hello,
    I am thinking the best way to do this will be analog. What i mean is just choose two sets of coordinates, compute their slope and apply the rotation yourself. It will be the least painful if you don't need to repeat this frequently.
    Doing this autonomously will be quite a bit more difficult. There are ways to get it done, but guarenteeing good performance over your analog work will be difficult. Here is the way to do this analog:
    %you choose 2 coordinate sets on the image
    slope=(coord_1(2)-coord_2(2))/(coord_1(1)-coord_2(1)); %simple slope calculation
    %now we convert this to degrees.
    %assuming 90 is vertical and 0 is horizontal
    %perform the rotation
    Now to do this autonomouly will require some work. You will need to apply an image processing technique to segment the objects present, and identify the spine. You'll need to play around with the methods to see which one works the best. Here are some ideas that I have:
    1. Use a hough transform,this algorithm identifies lines in an image(see: Locate the longest line(which should be the spine, calculate its slope and perform the rotation). Try processing without the image pre processing ans see if you can detect the spine.
    %code for the Hough transform
    %this block gives the endpoints of the lines it locates.
    %try the Hough transform without the pre processing as well.
    image=rescale(image,0,1);%helps in binarization
    BW_finel=bwskel(BW_im); %create image skeleton
    [H,theta,rho] = hough(BW_final);
    P = houghpeaks(H,45,'threshold',ceil(0.1*max(H(:))));
    lines = houghlines(BW_im,theta,rho,P,'FillGap',5,'MinLength',7);
    %lines is a struct, stick this in a for loop to extract
    for i=1:length(lines)
    %parse for the longest one to identify the spine.
    2. Use Haar like features
    All of these methods except 4, will require you to parse the output and figure out the slope of the spine, then apply the rotation. A Haar like feature(just google these), can be used to identify objects. Here, we will construct one for the spine, and rotate it in intervals of 5 degrees(you can change this). The Haar like features will convolute the image, and whichever angle yields the highest value(from the convolution) will give a +-2.5 degrees on your spine angle. The following block of code explains how to use a Haar like feature and the logic to determine the rotation.
    image=rescale(image,0,1); %helps with speed and other things
    spine_average_width=30; %this is in pixels, change for your need(tune it)
    spine_average_height=100;% in pixels change for your need(tune it)
    %we have created a binari image with a vertical bar. this is our Haar like feature
    %you'll need to add a little routine to make sure the rotation is upwards
    for i=1:18 %starting from vertical going horizontal
    angle=index*5; %because 5 degrees per iteration
    I hope this answer is not overbearing, i just like medical imaging problems and think they're fun to solve.
    Hope this helps,