Skin lession boundary tracing algorithm

I found a Matlab to be a convenient tool which allows easily to trace boundaries of objects in a picture. So I adopted it to skin lesions. This can be used for automatic detection of skin irregularities and utilized to calculate lesion properties like the asymmetry of shape, or border irregularities, who can help in detecting melanoma. There are numerous investigations done, so I only put a few examples of how it looks. I will give you my source code so that you can try it on your own.

Look at my results:

1)

traced

And it also finds the center of mass:

geocenter

 2)

traced_02

and center of mass:

geocenter_01

3)

traced_03

Here is my source code:

%----------------------------------

clear all
close all
clc
%k parameter can be changed to adjust intensity of image
ei=25;
st=35;
%k=10
k=ei*st;
I = imread('1.jpg');
%h=filter matrx
h = ones(ei,st) / k;
I1 = imfilter(I,h,'symmetric');
figure
subplot(2,2,1),imshow(I), title('Original image');
subplot(2,2,2), imshow(I1), title('Filtered Image');
IG=rgb2gray(I1);
%Converting to BW
I11 = imadjust(IG,stretchlim(IG),[]);
level = graythresh(I11);
BWJ = im2bw(I11,level);
dim = size(BWJ)
IN=ones(dim(1),dim(2));
BW=xor(BWJ,IN);  %inverting
subplot(2,2,3), imshow(BW), title('Black and White');
%Finding of initial point
row = round(dim(1)/2);
col = min(find(BW(row,:)))
%Tracing
boundary = bwtraceboundary(BW,[row, col],'W');
subplot(2,2,4),imshow(I), title('Traced');
hold on;
%Display traced boundary
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
hold off
% figure
% plot(boundary(:,2),boundary(:,1),'black','LineWidth',2);

nn=size(boundary);
KM=zeros(dim(1),dim(2));
 ii=0;
 %Create new matrix with boundary points. there fore we can get rid off
 %other distortions outside boundaries
 while ii<nn(1)
     ii=ii+1;
    KM(boundary(ii,1),boundary(ii,2))=1;
end
 figure
 subplot(2,2,1),plot(boundary(:,2),boundary(:,1),'black','LineWidth',2);
 subplot(2,2,2),imshow(KM)
%Fill inner boundaries where lesion is located
KM2 = imfill(KM,'holes');
subplot(2,2,3),imshow(KM2)
KM1=xor(KM2,IN);
% subplot(2,2,4),imshow(KM1)
%Geometrical center
IVx=[1:dim(2)];
IVy=[1:dim(1)];
IMx=ones(dim(1),1)*IVx;
IMy=ones(dim(2),1)*IVy;
IMy = imrotate(IMy,-90);
Koordx=IMx.*KM2;
Koordy=IMy.*KM2;
xmean=mean(Koordx,2);
yc=round(sum(xmean.*IMy(:,1))/sum(xmean));
ymean=mean(Koordy);
xc=round(sum(ymean.*IVx)/sum(ymean));
figure
imshow(I)
hold on
plot(boundary(:,2),boundary(:,1),'green','LineWidth',2);
hold on
plot(xc,1:dim(1),'red','LineWidth',2);
plot(1:dim(2),yc,'red','LineWidth',2);
hold off
% ID=im2double(I);
ID1(:,:,1)=im2double(I(:,:,1));
ID1(:,:,2)=im2double(I(:,:,2));
ID1(:,:,3)=im2double(I(:,:,3));
 figure
subplot(2,2,1), imshow(ID1);
subplot(2,2,2), imshow(ID1(:,:,1));
hold on
plot(xc,1:dim(1),'red','LineWidth',2);
plot(1:dim(2),yc,'red','LineWidth',2);
hold off
subplot(2,2,3), imshow(ID1(:,:,2));
subplot(2,2,4), imshow(ID1(:,:,3));

%---------------------------------

 

46 Comments:

  1. What language?

  2. Oh.. matlab? nevermind.

  3. No I didn’t test. Actually My intention was to do so, but later I decided to do research on skin reflection spectra analysis. Some result you may see in this page. Later I think I will add more details.

  4. you can try it in . “GNU Octave is a high-level language, primarily intended for numerical computations mostly compatible with Matlab.”

  5. This is great, I had this brainstorm a while back that if you had an algorithm like this people could use their digital cameras to compare this year/last year pictures (take your green line and compare with a red line for this year) Great job!

  6. Hello, I am currently working on a research project at the University of Missouri-Rolla where we are trying to use digital image processing to identify skin cancers from benign lesions. As of now we have been using manual border drawing. I was wondering if you have tested this on a large selection of images to see if it is “fool-proof”?

  7. GNU Octave is not as user-friendly as Matlab. I typically like the fact about MATLAB is that it has several toolboxes with different numerous algorithms which developers (like myself) can always select from. I am interested what kind of algorithms do you choose from in this example here?

  8. How would people in the normal world who are not familiar with Matlab (me) use this?

  9. Can you explain why the ‘symmetric’ filter is used instead of any ‘Average’ or ‘gaussian’ filter. Also, why use Traceboundary function instead of Edge function with ‘sobel’ or ‘canny’ ? Thanks

  10. So it just uses thresholding to find the border? In my image processing classes we studied stuff like predictive non-maxima suppression to find edges. Not sure if matlab does it inherently, but it’s what’s used to separate objects in motion tracking and other examples.

  11. The point is MATLAB is commercial software and an expensive one at that, especially when you start adding various toolboxes (functions) to the base product. Not any Tom , Dick and Harry could afford this product, it may be better done using JAVA, together with Java Advanced Imaging API or the free OpenCV.

  12. That is some hardcore code! Well done.
    Really impressive!


    web design uk

  13. Frank the Ferret

    Great, you provided me with an idea for the webcam based image recognition and aiming algo i need to construct a self cleaning ferret toilet.

    1. use unsharpen or blur Filter
    2. Black and white filter with threshold
    (maybe multiple tries with different settings)
    3. Analyze each line for black/white changes
    which wille give points of a polygon
    4. Calculate the area of the poly. Don’t want to
    hurt the ferret with litter falling on it.
    5. Find center of gravity of the polygon
    or a surroundig circle to aim litter canon
    6. Construct some Lego robot

    1. and 2. can be done by calling e.g. IrfanView
    in commandline/batch mode.
    3. shouldn’t be hard with a two colored .bmp
    4. and 5. algos should float around the web
    or just use Monte Carlo like pixel counting
    6. The next funny challenge. Maybe i can reuse
    some parts from a homemade plotter constructed
    from threaded rods.

    Yes, it is pretty homebrew project, but see it as applied science.

    Thank you, Klaas

  14. Adaboost based object detection can be used to find multiple lesions of various sizes and shapes on varying leison colors and backgrounds(skin colors). This would generate a quantitative and qualitative study of the matter.

  15. Hello there
    how are you?
    my name is Atiqah and i am doing my final
    year electrical engineering course in Malaysia (Universiti Teknologi Petronas)
    For ur information, my project is to design an automated PASI scoring for psoriasis skin disease using matlab, program that can generate score of redness of psoriasis lesion. Im glad i have found ur blog, it will be a great help if you could send me the matlab codes of this project and other informations related to it.What have you done is great..really great =)Wish to here from you..feel free to contact me via my email address

    Thanks friend =)

  16. I could you send some matlab codes, but they are not in one peace. My work was split in parts and they are not put in together…
    This tracing algorithm is separate investigation. it is as you see in my blog.

  17. hello there!! same like atiqah, ur work has helped me a lot with my digital processing project, it’s more to f&b and medicinal product quality inspection(by focusing on shape and dimension) like capsules,i’d be really really really16x thrilled if you can send me your other work too!! it doesn’t matter if they’re separated!! thx a bunch =)

  18. hello there!! like atiqah ur work has helped me tremendously! i’m doing this project on machine vision–to check the quality of f&b or medicinal product like capsules, by comparing shapes and dimensions and all. however i proposed that it will done in real-time, meaning i would have a webcam connected to my pc and let matlab checks and checks continuously, do u have any suggestion on this? and i would be grateful if u would send ur other works to me too, itz ok if they’re separated, hehe.. really16x thk u if u do that!! =)

  19. Hi, i’m doing a similar project to this and i tried to run your code on matlab, but i get an error like “Undefined function or variable ‘bwtraceboundary'”. I assume ‘bwtracedboundary’ is a pre-defined function in matlab? It would be nice if you could help me out.

    Also what kind of alogrithm you are implementing?

  20. i need a help..i want to detect the outer boundary on the object..coz i want to find pixel value for the outer boundary..the matlab code is helpful,but can i have it in java?

  21. would u please 2 translate that source code to delphi language?please….N please sent them to my mail.thaks so much.

  22. same with rio hendri, would translate it, because i never try with matlab

  23. This is a great tool for helping people monitor themselves in between dermatologist visits.

  24. hey its great! have u worked on any other algorithms… i would want to look at the source code…

  25. Hi, i’m doing a similar project to this and i tried to run your code on matlab, but i get an error like “Undefined function or variable ‘bwtraceboundary’”. I assume ‘bwtracedboundary’ is a pre-defined function in matlab?.i use matlab 6.5.please help!!

  26. Use 7th version of matlab. 6.5 doesn’t have this function.

  27. Hi, you have an interesting job here, im working on image processing too. I’ve seen that you use a polarized filter, did you use it in this examples? or you use characterized images? Right now im working on leg ulcers and i have some troubles with the skin texture and lighting, do you have some information about it? i need to find the real border of the skin lesion, thanks in advance.

  28. Hi,

    I am a medical student at University of Pittsburgh. I am attempting to do a research project to show a simple hypothesis; that changes in skin pigmented lesions (moles) are detectable through sequential photographs. In order to do so, I’m looking for software(s) that can do two things.

    1) Given two photographs of the posterior trunk upper scapular region (upper back); the software would correctly match up mole 1 on photograph 1 with mole 1 on photograph 2.

    2) Given a large photograph, analyze each mole and give me data on each mole. For example, data on border, diameter, color, etc.

    Any help would be much appreciated. Please email chinhungho@gmail.com or ho.chin@mail.medstudent.pitt.edu.

    Thanks!
    Chin

  29. hi,i want to ask whether we need to determine the initial point ourselves or let the program to determine it?
    thank you

  30. hi i am doing digital image processing using matlab so i need ur help… so can u please send the source code for it

  31. Hi,I am a final year E&TC engg student and our project topic is ‘Diagnosis of Skin Cancer using Digital Img Processing’ techniques.Your blog was our source of inspiration and I would like to thank you for sharing your knowledge with us.We are planning to use ABCD parameters and code in MATLAB.If time permits,we’ll do it in C also.I also wanted to know if this blog is still being updated regularly so that we can share our progress as well as problems with you.
    Thanks again!

  32. kobinathan katan

    hi im kobinathan.actualy im doing my thesisis on image processing.so i hopr u can help me.my topic is Visualization of cancer cell.Help me.

  33. I am doing project in Matlab in which i am trying to recognize the part of skin which is defected from the whole skin.
    Plz give me the matlab code for the same ..

  34. Hi,
    I’m very excite by what you’re doing here. I did some research using geometric invariants to look at image processing. It’s a way to come up with an aspect of an image that is invariant to rigid movements of the object. I did something similar with blood cells. The great thing about image invariants is that the image of a circular shape is a point and the image of an irregular shape then will deviate from that point. I’d be very interested to read more of you work.

  35. Hey,
    If anyone has a large quantity of stock photos of lesions. I would love to be able to do research with them. You can e-mail me at
    ojal0011 umn edu

  36. fine post about skin cancer and reason of skin cancer

  37. hi,
    Yet another student, found my way here by googling to find algorithms about the ABCDs of melanoma. My project is to compose an algorithm about each one of them on Matlab and seems that your source code is what i should start with… If you can send me any other work you have done regarding skin lesions(i mainly need codes like this one), as well as photos of lesions i would be greatly appreciative. Thanks again and this is a damn good work here!
    my email is alexskeb9@hotmail.com

  38. hye.im fathiyah. I’m a final year project titled skin care diagnosis system which uses image processing to study the type of human skin (face). I am very proud of where you find blog is very useful for me. I am very proud if you can send the matlab codes of this project and other informations related to it to me to my email. your work very good. feel free to contact me via my email address

  39. hai..can you explain the standarad values of abcd parameters while going for the detection of skin cancer?

  40. Hai i am doing my project in cancer diagonistis by using image processing Plz help me if u Have model code Plz mail me my address is blessinghfeb2@gmail.com

  41. please tell me the idl code for calculate the threshold value to segmet the skin cancer image

  42. sir,
    hi, it’s working well. can I know wat algorithm is used here.
    plz clear my doubt.
    I’m doing my project in face detection area. for that i find the two points one is center point(nose ) and another one the center point of the fore head . by using these points i have to draw a oval shape and also center of the mass. it is possible or not.

  43. Hi i m doing my final year project on skin cancer identification using Matlab. I am working on malignant malanoma using the ABCD algorithm I have done the detection part but not understanding about the measurement of its parameter. Can you suggest about it?

  44. hi
    i m doing final year project on center of gravity in swimming start.i use this nice code to calculate center of gravity in 2d.do you can help me to be better.do you have idea about this.
    i m from iran,univercity of mazandaran.
    i m study biomechanics.thanks dear.

  45. hi there! I m doing my PG project on lesion segmentation. I request you to plz send me code for preprocessing of dermoscopic images. It will be very helpful to me. thnx

  46. Good Work..
    How can i calculate the ABCD values from the output image.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.