Novel Method for Determining Symmetry of Skin Lesions using the Jaccard Index

This Script is useful in finding symmetry lines in Skin Lesions with extensions to any binary masks.
635 Downloads
Updated 19 May 2015

View License

**This script is a prototype. It works very well on the test images I used. I included two of them in the .zip. In a later upload I am going to overlay the symmetry lines on the RGB image of the lesion so as to better see where the lines exist. This is a continuation of my series of algorithms that have focused on skin lesions.
For those interested I have also developed an algorithm for counting colors in a skin lesion:
https://nl.mathworks.com/matlabcentral/fileexchange/50872-function-for-counting-colors-in-a-skin-lesion

and I have developed an algorithm that simply segments the skin lesion:
https://nl.mathworks.com/matlabcentral/fileexchange/50698-a-hybrid-skin-lesion-segmentation-tool--using-pca-and-iterative-canny-edge

These scripts are good starts toward a fully automatic skin cancer diagnostic tool based on ABCD criteria.

This script in particular can be modified to find lines of symmetry or similarity in binary image.

Below is my script for determining the number of symmetry/similarity lines in a skin lesion. This is the first time the Jaccard Index has been applied to skin lesions.

Feel free to comment and let me know how you have used it in your work or research.

This algorithm is copyrighted by Tyler L. Coye (2015). Commercial use or publication is not authorized without the author's approval.

Here are the general steps in the script below:

1. Input RGB image of Skin Lesion
2. Skin Lesion is segmented using an method I developed before and can be found on File Exchange
3. A binary mask is created and the skin lesion is cropped out.
4. The cropped image is rotated 2 degrees from 0 to 360.
-At each 2 degree increment the image is flipped from left to right, resulting in A and A'.
-A Jaccard index and distance is calculated for A and A'
-Depending on the distance ( <.072 or 92.8% similarity), a symmetry line is either drawn or not.
-This is done until the image has finished rotation.
5.The final count is outputted in the command window & the symmetry lines are drawn on the rotated images to show where they exist.

NOTE: generally there are degrees that represent the same symmetry line, to overcome this, I divided the count by 2 to result in the final count.

Your input should be an RGB image. For best results, it should be of a skin lesion of moderate size, say 300 x 300 or so. Larger images should be scaled down. If your skin lesion has hair, I would add the razor filter to the script below. This script does not work on skin lesions obstructed by hair.

clear all
%% ***PART I-SEGMENTATION***
% Read image
I = imread('test3.jpg');
im = im2double(I);
% Convert RGB to Gray via PCA
lab = rgb2lab(im);
f = 0;
wlab = reshape(bsxfun(@times,cat(3,1-f,f/2,f/2),lab),[],3);
[C,S] = pca(wlab);
S = reshape(S,size(lab));
S = S(:,:,1);
gray = (S-min(S(:)))./(max(S(:))-min(S(:)));
% Morphological Closing
se = strel('disk',1);
close = imclose(gray,se);
% Complement Image
K= imcomplement(close)
% 2-D wavelet Decomposition using B-Spline
[cA,cH,cV,cD] = dwt2(K,'bior1.1');
%% Otsu thresholding on each of the 4 wavelet outputs
thresh1 = multithresh(cA);
thresh2 = multithresh(cH);
thresh3 = multithresh(cV);
thresh4 = multithresh(cD);
% Calculating new threshold from sum of the 4 otsu thresholds and dividing by 2
level = (thresh1 + thresh2 + thresh3 + thresh4)/2;
% single level inverse discrete 2-D wavelet transform
X = idwt2(cA,cH,cV,cD,'bior1.1')
% Black and White segmentation
BW=imquantize(X,level);
% Iterative Canny Edge (Novel Method)
BW1 = edge(edge(BW,'canny'), 'canny');
% Post-Processing
BW3 = imclearborder(BW1);
CC = bwconncomp(BW3);
S = regionprops(CC, 'Area');
L = labelmatrix(CC);
BW4 = ismember(L, find([S.Area] >= 100));
BW51 = imfill(BW4,'holes');
BW5 = imcomplement(BW51);
imgbw = bwlabel(BW51);
ss_mask = bwlabel(imgbw);
stats = regionprops(ss_mask, 'BoundingBox', 'Area' );
Astats = [stats.Area];
idx = find(Astats == max(Astats));
ss_mask = ismember(ss_mask, idx);
out_img = imcrop(BW51, stats(idx).BoundingBox);
%% Search for Number Symmety Lines using Jaccard Similarity Coefficient
count = 0
for k=0:2:360
B = imrotate(out_img,k)
C = fliplr(B)
intersect = B & C;
union = B | C;
numerator = sum(intersect(:));
denomenator = sum(union(:));
jaccardIndex = numerator/denomenator
jaccardDistance = 1 - jaccardIndex
if jaccardDistance < .072 % you can change this value ( The closer to zero, the more similar)
count = count + 1;
figure;
hold on;
D = imresize(B, 2)
[m n] = size(D)
imshow(D);
line([m/2,m/2],[0,n],'Color','r','LineWidth',2)
text(0,-12,strcat('\color{blue}\fontsize{16}Degrees:',num2str(k)))
hold off
end
end
final_count = count/2 % Generally you will get 2 k's that correspond to the same line, so you divide by 2.

Cite As

Tyler Coye (2024). Novel Method for Determining Symmetry of Skin Lesions using the Jaccard Index (https://www.mathworks.com/matlabcentral/fileexchange/50903-novel-method-for-determining-symmetry-of-skin-lesions-using-the-jaccard-index), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

Symmetry/

Version Published Release Notes
1.0.0.0

summary update
Text update
updated description
updated text

updated text
text update