Code
import os,re,zipfile
# data manipulation packages
import pandas as pd
import numpy as np
from PIL import Image
# data viz
import matplotlib.pyplot as plt
import seaborn as sns
'seaborn')
plt.style.use('whitegrid') sns.set_style(
Daniel Fat
December 20, 2020
This set consists of 2357 images of malignant and benign oncological diseases, which were formed from The International Skin Imaging Collaboration (ISIC).
All images were sorted according to the classification taken with ISIC, and all subsets were divided into the same number of images, with the exception of melanomas and moles, whose images are slightly dominant.
The data set contains the following diseases:
Imports
Download the dataset from Kaggle
CPU times: user 19 µs, sys: 5 µs, total: 24 µs
Wall time: 28.6 µs
Unzip the dataset
Paths to Train & Test folders
Create a dataframe with filename, filepath and the disease type
filename | filepath | label | |
---|---|---|---|
0 | ISIC_0025915.jpg | /content/skin-cancer9-classesisic/Skin cancer ... | pigmented benign keratosis |
1 | ISIC_0024947.jpg | /content/skin-cancer9-classesisic/Skin cancer ... | pigmented benign keratosis |
2 | ISIC_0026539.jpg | /content/skin-cancer9-classesisic/Skin cancer ... | pigmented benign keratosis |
let’s pick a sample image of melanoma
now we want to load the image using the pillow
package
then we want to convert the image object into a numpy array
finally we want to print our image
Image as data
A RGB image has 3 color channels as the RGB (Red, Green, Blue). Those 3 channels are 3 different matrices of with pixel values inside, and overlaying them we can get a normal image as we know.
let’s try to extract and see the image through each one of this channels
here we can see that the clearest image of the melanoma is on the blue channel, for segmenting the melanoma from this image we want to convert the image into black and white
For an erosion, you examine all of the pixels in a pixel neighbourhood that are touching the structuring element. If every non-zero pixel is touching a structuring element pixel that is 1, then the output pixel in the corresponding centre position with respect to the input is 1. If there is at least one non-zero pixel that does not touch a structuring pixel that is 1, then the output is 0.
Dilation is the opposite of erosion. If there is at least one non-zero pixel that touches a pixel in the structuring element that is 1, then the output is 1, else the output is 0. You can think of this as slightly enlarging object areas and making small islands bigger.
Results
Here we can see how we can highlight the mask for the cancer spots
fig,(ax1, ax2, ax3) = plt.subplots(1,3,figsize=(14,7))
ax1.imshow(img_arr);
# draw contour around the mask
ax2.imshow(segmentation.mark_boundaries(img_arr, np.ma.masked_where(erosion == 0, erosion)));
# we reverse the pixels and show the eroded mask over the original image
ax2.imshow(np.ma.masked_where(erosion == 0, erosion),'RdBu', alpha=0.7, interpolation='none')
# draw contour around the mask
ax3.imshow(segmentation.mark_boundaries(img_arr, np.ma.masked_where(dilation == 0, dilation)));
# we reverse the pixels and show the dilated mask over the original image
ax3.imshow(np.ma.masked_where(dilation == 0, dilation),'RdBu', alpha=0.7, interpolation='none')
ax1.set_title('Original Image')
ax2.set_title('Eroded Image')
ax3.set_title('Dilated Image')
plt.tight_layout();