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

Version 1.0.0.0 (10.2 KB) by
This Script is useful in finding symmetry lines in Skin Lesions with extensions to any binary masks.

Updated 19 May 2015

**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***
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);
stats = regionprops(ss_mask, 'BoundingBox', 'Area' );
Astats = [stats.Area];
idx = find(Astats == max(Astats));
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 (2023). 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.77551097,"math_prob":0.9301118,"size":5906,"snap":"2023-14-2023-23","text_gpt3_token_len":1561,"char_repetition_ratio":0.08980007,"word_repetition_ratio":0.018285714,"special_character_ratio":0.26379952,"punctuation_ratio":0.15180935,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97859573,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-07T11:32:40Z\",\"WARC-Record-ID\":\"<urn:uuid:e6dd6f59-d7e1-412f-94ff-0996cf7ce478>\",\"Content-Length\":\"95207\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:153c1f23-2084-439f-9398-ba6e028f3dfb>\",\"WARC-Concurrent-To\":\"<urn:uuid:8fb2a4d0-65c3-4b8d-8f3b-9a3d37bf718e>\",\"WARC-IP-Address\":\"104.86.80.92\",\"WARC-Target-URI\":\"https://www.mathworks.com/matlabcentral/fileexchange/50903-novel-method-for-determining-symmetry-of-skin-lesions-using-the-jaccard-index?s_tid=blogs_rc_6\",\"WARC-Payload-Digest\":\"sha1:LT2IRIFMNUECRELSENTKP545YRX4E2V5\",\"WARC-Block-Digest\":\"sha1:KUFCYGYT7VBXS5VUKSC5UPCTZV6VXAWY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224653764.55_warc_CC-MAIN-20230607111017-20230607141017-00598.warc.gz\"}"}