0% found this document useful (0 votes)
5 views48 pages

Report

The project report presents a Deep Learning approach for the detection and classification of lung cancer using CT scans, focusing on improving early diagnosis and treatment outcomes. It employs Convolutional Neural Networks (CNNs) for feature extraction and classification, achieving high accuracy in identifying different types of lung cancer. The framework is designed to integrate seamlessly into existing medical imaging systems, enhancing the capabilities of clinicians in making timely treatment decisions.

Uploaded by

jeevankumars786
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views48 pages

Report

The project report presents a Deep Learning approach for the detection and classification of lung cancer using CT scans, focusing on improving early diagnosis and treatment outcomes. It employs Convolutional Neural Networks (CNNs) for feature extraction and classification, achieving high accuracy in identifying different types of lung cancer. The framework is designed to integrate seamlessly into existing medical imaging systems, enhancing the capabilities of clinicians in making timely treatment decisions.

Uploaded by

jeevankumars786
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

Jnana Sangama, Belagavi,Karnataka - 590 018.

A Project Work Report on

“Lung Cancer Detection and Classification


using Deep Learning”
Submitted in partial fulfillment of the requirements for the award of the degree of
Bachelor of Engineering
in
Electronics and Communication Engineering
by
Jeevan Kumar S USN:4JN20EC039
Karthik L M USN:4JN20EC040
Koushik M T USN:4JN00EC042
Sathyanarayana S R USN:4JN20EC065

Under the Guidance of


[Link] .P [Link].,Ph.D.
Professor and Dean Academics,
Dept. of ECE, JNNCE, Shimoga-577 204.

Department of Electronics and Communication Engineering


JNN College of Engineering, Shimoga - 577 204.

May 2024
VISVESVARAYA TECHNOLOGICAL UNIVERSITY
Jnana Sangama, Belagavi-590 018.
JNN College of Engineering
Department of Electronics and Communication Engineering
Shimoga-577 204.

CERTIFICATE
This is to certify that the project work entitled ““Lung Cancer Detection and Classi-
fication using Deep Learning”” is carried out by Jeevan Kumar S (4JN00EC039),
Karthik L M (4JN00EC040), Koushik M T (4JN00EC042), Sathyanarana S
R (4JN00EC065) , the bonafide students of JNN College of Engineering, Shimoga in
partial fulfillment for the award of “Bachelor of Engineering” in department of “Elec-
tronics and Communication Engineering” of the Visvesvaraya Technological University,
Belagavi, during the year 2023-24. It is certified that all the corrections/suggestions
indicated for internal assessment have been incorporated in the report deposited in the
departmental library. The project report has been approved as it satisfies the academic
requirements in respect of project work prescribed for the said degree.

Signature of the Guide Signature of the Coordinator


[Link].P [Link] S B
Professor and Dean Academics, Assistant Professor
Dept. of ECE,JNNCE, Shimoga. Dept. of ECE,JNNCE, Shimoga.

Signature of the HoD Signature of the Principal


Dr. S.V. Sathyanarayana Dr. Y. Vijaya Kumar
Professor & HoD Principal
Dept. of ECE,JNNCE, Shimoga. JNNCE, Shimoga.
External Viva

Name of the examiner Signature with date


1.

2.
ABSTRACT

Lung cancer is one of the most prevalent and fatal cancers worldwide, with early detec-
tion playing a crucial role in improving patient outcomes. In this project, we propose a
Deep Learning-based approach for the detection and classification of lung cancer from
medical imaging data using CT scans. Our model leverages Convolutional Neural Net-
works (CNNs) to automatically extract features from lung images, enabling accurate
classification of cancerous and non-cancerous regions.
The proposed system consists of three main stages: preprocessing, feature extraction,
and classification. In the preprocessing stage, we employ various image enhancement
techniques to standardize and improve the quality of input images. Next, a pre-trained
CNN architecture is utilized to extract discriminative features from the preprocessed
images. Finally, these features are fed into a classifier to distinguish between different
types of lung cancer, including adenocarcinoma, squamous cell carcinoma,large cell car-
cinoma and normal one. CT screening has been proven to be effective for diagnosing
lung cancer at its early manifestation in the form of pulmonary nodules, thus decreasing
the [Link] proposed model achieves high accuracy, sensitivity, and specificity in
identifying various types of lung cancer, thereby aiding clinicians in making timely and
informed treatment decisions. Additionally, the proposed framework can be easily inte-
grated into existing medical imaging systems, providing a valuable tool for early diagnosis
and personalized treatment of lung cancer.
Keywords: Lung cancer,CT scan,CNN,Image Processing,Deep Learning;

i
ACKNOWLEDGEMENTS

The satisfaction and euphoria that accompany the successful completion of any task
would be incomplete without the mention of the people who made it possible whose
constant guidance and encouragement crowned the efforts with success. I thank Dr.Y
Vijaya Kumar, Principal, and Dr. Manjunatha P, Dean Academics JNNCE, Shiv-
amogga for giving facilities to undertake internship work. I would like to express my
gratitude to Dr. S.V Sathyanarayana, Head of Department, Electronics and Com-
munication Engineering for providing a good working environment and for his constant
support and encouragement. It gives me great pleasure in placing on record a deep sense
of gratitude to our guide Dr. Manjunatha P, Professor and Dean Academics and to our
Project coordinator, Mrs. Nalina S B, Assistant Professor, Department of Electronics
and Communication Engineering for their expert guidance, initiative and encouragement
that led me through the presentation. And lastly, I would hereby acknowledge and thank
my parents who have been a source of inspiration and also instrumental in the successful
completion of the technical seminar.

Jeevan Kumar S
Karthik L M
Koushik M T
Satyanarayana S R

ii
Contents

Abstract i

Acknowledgements ii

List of Figures v

1 Preamble 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Aim of the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Scope of the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Limitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 Organization of the report . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Theoretical Background 7
2.1 Literature survey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Conclusion of the literature . . . . . . . . . . . . . . . . . . . . . . . . . 11

3 Design and Implementation 12


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Convolution operation over the input image . . . . . . . . . . . . . . . . 16
3.4 Kernel function over Feature extraction . . . . . . . . . . . . . . . . . . . 17
3.5 Description Of Libraries and Software . . . . . . . . . . . . . . . . . . . . 18
3.6 Flow chart for training . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.7 Flow chart for the testing and validation part . . . . . . . . . . . . . . . 22
3.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

4 Results and Disscusion 24


4.1 Data collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2 Preprocessing stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.3 Model training . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.4 Detection of lung cancer type and Remedies . . . . . . . . . . . . . . . . 27

iii
5 Conclusion 28

A Appendix 29
A.1 Program for training the model . . . . . . . . . . . . . . . . . . . . . . . 29
A.2 Program for testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

References 41

iv
List of Figures

1.1 Mortality rate in recent years due to different cancers . . . . . . . . . . . 1


1.2 Model Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3.1 CNN Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


3.2 Input data set(CT scan images). . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4 Preprocessing stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5 Convolution over the input image . . . . . . . . . . . . . . . . . . . . . . 16
3.6 Diagram A to C is an example of convolution operation with a kernel size
of 3x3, . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.7 Flow chart for training part of the project. . . . . . . . . . . . . . . . . . 20
3.8 flow chart for the testing of the unseen data . . . . . . . . . . . . . . . . 22

4.1 Collection of Data set of different type of lung cancer . . . . . . . . . . . 24


4.2 Preprocessing views of the input . . . . . . . . . . . . . . . . . . . . . . . 25
4.3 Graph of Accuracy and loss . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4 lable name with different probability values . . . . . . . . . . . . . . . . . 26
4.5 Model training values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.6 Detection of the type of cancer and its remedies . . . . . . . . . . . . . . 27

v
Chapter 1

Preamble

1.1 Introduction
Lung cancer is a significant public health concern globally, accounting for a substantial
portion of cancer-related deaths each year. Early detection and accurate classification
of lung cancer are crucial for timely intervention and improved patient outcomes. Tra-
ditional methods for diagnosing lung cancer, such as visual inspection of medical images
by radiologists, are time-consuming and subject to inter-observer variability.

Figure 1.1: Mortality rate in recent years due to different cancers

The mortality rate for lung cancer in past 4 years is estimated to be 1,761,007, which
will increase to 3,104,704 in 2040. As seen in the figure, the incidence of lung cancer in
men and women will also increase and the number of deaths from lung cancer in men in
recent years will increase up to 2,372,239 and in women from 725,352 to 1,238,657 Based
on the results of cancer registries in past 4 years, the highest incidence and mortality
rates are from lung cancer (42.2 percent of new cases and 38.1 perecnt of deaths)[Link]
development of this type of models will help in the early screening and treatment of the

Dept. of ECE, JNNCE, Shimoga May-2024 1


1. Preamble

patient in the early stages.

In recent years, Deep Learning has emerged as a promising tool for medical image anal-
ysis, offering the potential to automate and enhance the accuracy of cancer detection and
classification tasks. Deep Learning algorithms, particularly Convolutional Neural Net-
works (CNNs), excel at learning intricate patterns and features from complex image data,
making them well-suited for tasks such as lung cancer detection and [Link]
project focuses on the development of a Deep Learning-based system for the automated
detection and classification of lung cancer from medical imaging data. By harnessing
the power of CNNs, we aim to create a robust and efficient solution capable of accu-
rately identifying various types of lung cancer, including adenocarcinoma, squamous cell
carcinoma,large cell carcinoma and normal [Link] proposed system comprises several
key components, including preprocessing techniques to enhance image quality, feature
extraction using CNNs to capture relevant patterns, and classification algorithms to dif-
ferentiate between different types of lung cancer. By integrating these components into
a unified framework, we seek to streamline the diagnosis process and provide clinicians
with valuable insights for personalized treatment planning.
Through this project, we envision contributing to the advancement of lung cancer
diagnosis by leveraging state-of-the-art Deep Learning techniques. The ultimate goal is
to facilitate early detection, improve treatment outcomes, and reduce the burden of lung
cancer on individuals and healthcare systems worldwide.

1.2 Aim of the project


Lung Cancer Detection and Classification Using Deep Learning

1.3 Objectives
ˆ To collect the different CT scaned images of lung cancer patients to form data set.

ˆ To detect whether the CT scan image of patient is cancerous or not.

ˆ To classify which type of cancer.

Dept. of ECE, JNNCE, Shimoga May-2024 2


1. Preamble

1.4 Methodology
The methodology of detection and classification of lung cancer by deploying a CNN model
for training and softmax for prediction and also classification involves several steps.

Figure 1.2: Model Architecture

Data Collection:
The first step is to collect a large dataset of CT scan images, some labeled as lung
cancer-positive and others as [Link] a dataset for a project like lung cancer
classification using CT scan images involves several steps, including acquiring the images,
labeling them, and organizing them into appropriate directories.
Label each CT scan image according to its diagnosis ( adenocarcinoma(a), squamous cell
carcinoma(s),large cell carcinoma(l) and normal(n)). This can be a time-consuming pro-
cess and may require input from medical professionals or radiologists to ensure accuracy
for the model training process.

Data Preprocessing: Large images cannot be fed directly into convolutional neural
network architecture because of the limit on the computation power. At first, we con-
verted all the images into similar size and format. To reduce the size of the input data,
we have segmented the [Link] have to find the regions that are more probable of
having cancer. We have reduced our search space by first segmenting the lungs and then
removing the low intensity regions(also called as the non-data regions).

Model Architecture: Design a CNN architecture suitable for image classification tasks.

Dept. of ECE, JNNCE, Shimoga May-2024 3


1. Preamble

The architecture of the CNN model consists of several layers, including convolution lay-
ers, rectified linear unit (ReLU) layers, response normalization layers, and pooling layers.
The input images are down-sampled to reduce the computational complexity of the deep
learning architecture.

Training the Model: The CNN model is trained using the preprocessed images and
their corresponding labels. During training, the model learns to extract relevant features
from the images and map them to their corresponding labels. The training process also
involves optimizing the model’s parameters to minimize the loss function.

Model Evaluation: After training, the model’s performance is evaluated using a sep-
arate validation dataset to ensure it generalizes well to unseen data. Additionally, it is
tested on another set of unseen data to measure its performance metrics such as accu-
racy, [Link] model can be further fine-tuned by adjusting the hyperparameters or
adding regularization techniques to improve its performance.

Prediction: After rigorous training and evaluation, the deep learning model demon-
strates promising performance in the task of lung cancer detection and classification.
Leveraging a diverse dataset comprising CT scans. the model exhibits high accuracy,
sensitivity, and specificity in identifying various types of lung cancer, including adeno-
carcinoma, squamous cell carcinoma, small cell carcinoma, and large cell carcinoma.
Through the integration of advanced preprocessing techniques, such as normalization,
noise reduction, and contrast enhancement, the model effectively extracts relevant fea-
tures and discriminates between cancerous and non-cancerous regions within the lung
images.

1.5 Scope of the project


The scope of this project appears to be focused on developing a basic image classification
model to distinguish between different lung cancer types.

ˆ Gather a comprehensive dataset of medical images, including CT scans, represent-


ing various types of lung cancer and non-cancerous conditions. Preprocess the

Dept. of ECE, JNNCE, Shimoga May-2024 4


1. Preamble

images to standardize resolution, normalize intensity values, and enhance image


quality by edge detection and image sharpening.

ˆ Design and implement a deep learning architecture, such as a convolutional neural


network (CNN), tailored to the task of lung cancer detection and classification.
Train the model using the preprocessed dataset, optimizing hyperparameters and
regularization techniques to improve performance and generalizability.

ˆ Assess the performance of the trained model using appropriate evaluation metrics,
such as accuracy, sensitivity, [Link] the model through cross-validation
and external validation on independent datasets to ensure robustness and general-
izability.

ˆ Compare the performance of the deep learning model with existing methods and
clinical standards for lung cancer detection and classification. Conduct thorough
benchmarking studies to highlight the strengths and limitations of the developed
approach.

ˆ Identify opportunities for further research and development to enhance the model’s
performance, scalability, and applicability. Explore potential collaborations with
industry partners, academic institutions, and healthcare organizations to advance
the field of lung cancer diagnosis and improve patient care outcomes.

1.6 Limitation
[Link] Dataset Size: The project mentions a dataset of 547 images for training
and testing the CNN model. A small dataset may limit the model’s ability to generalize
well to unseen data and may lead to overfitting which some times also give an false
positive. Moreover, variations in imaging protocols and quality across different healthcare
institutions can introduce bias and affect model performance.
Generalizability to Clinical Practice: While the model may demonstrate high per-
formance in controlled research settings, its real-world applicability and generalizability
to diverse patient populations and clinical environments remain uncertain. Validation
in real-world clinical settings is necessary to assess the model’s efficacy and feasibility in
routine practice.

Dept. of ECE, JNNCE, Shimoga May-2024 5


1. Preamble

Performance Limitations: Despite advances in deep learning algorithms, limitations


such as overfitting, model interpretability, and robustness to adversarial attacks remain
significant challenges. Continuous efforts in model optimization, regularization, and ro-
bustness testing are necessary to address these limitations and improve model perfor-
mance.

Resource Requirements: Training deep learning models for medical image analysis
requires substantial computational resources, including high-performance computing in-
frastructure and specialized hardware (e.g., GPUs).

1.7 Organization of the report


The report is organized into five chapters, chapter 1 includes the introduction about
the project. Chapter 2 includes the theoretical background about the project. Chapter
3 includes the design and implementation of “Lung Cancer Detection and Classification
using Deep Learning”. Chapter 4 includes Results and discussion of the project. Chapter
5 includes the conclusions of the overall project.

Dept. of ECE, JNNCE, Shimoga May-2024 6


Chapter 2

Theoretical Background

2.1 Literature survey


Literature survey is the important part of the report as it gives a direction in the area
of research. It helps to set a goal for analysis thus giving problem statement.
[1] Wankhade S and Vigneshwari proposed “A novel hybrid deep learning
method for early detection of lung cancer using neural networks”.
Lung cancer, characterized by its high mortality rate, presents a formidable challenge in
medical practice. Timely diagnosis and accurate staging are imperative for enhancing
patient outcomes and potentially saving lives. Despite the array of approaches, including
image processing, biomarker-based methods, and machine automation, employed to de-
tect lung cancer, achieving both accuracy and early diagnosis remains elusive for medical
professionals. In this context, the Lung Image Database Consortium and Image Database
Resource Initiative (LIDC-IDRI) serve as valuable resources, providing CT scan images
for research purposes. Traditionally, manual interpretation of CT images has been the
norm for detecting lung cancer. However, this research introduces a novel approach,
termed Cancer Cell Detection using Hybrid Neural Network (CCDC-HNN), aimed at
enabling early and precise diagnosis. Leveraging deep neural networks, features are ex-
tracted from CT scan images, a critical step in identifying cancerous cells at their incipient
stages, thereby offering a potential lifeline to patients. Moreover, the incorporation of
an advanced 3D-convolution neural network (3D-CNN) further enhances diagnostic ac-
curacy, enabling differentiation between benign and malignant tumors. Evaluation of
the results through standard statistical techniques confirms the efficacy of the proposed
hybrid deep learning (DL) technique in facilitating early lung cancer diagnosis.

This study underscores the pressing need for improved methods in lung cancer diagno-
sis, given its dire prognosis and significant impact on patient outcomes. The conventional
reliance on manual interpretation of CT images for detecting lung cancer underscores the
urgency for more sophisticated approaches. The proposed CCDC-HNN method, coupled

Dept. of ECE, JNNCE, Shimoga May-2024 7


2. Theoretical Background

with the utilization of deep neural networks for feature extraction, represents a significant
step forward in this endeavor. By enabling the detection of cancerous cells at early stages,
this approach holds promise for potentially altering disease trajectories and improving
patient survival rates. Furthermore, the integration of an advanced 3D-CNN augments
the diagnostic accuracy, thereby facilitating the crucial distinction between benign and
malignant tumors. The validation of results through rigorous statistical analysis under-
scores the reliability and effectiveness of the hybrid DL technique proposed in this study.
In summary, this research contributes to the ongoing quest for more precise and timely
lung cancer diagnosis, offering hope for better outcomes and enhanced patient care.

[2] Shashikala, Parveen, N, Maqbool, Khan, Alghadeer S.K. and Singh, G


proposed “A Novel Approach for Lung Cancer Detection Using Deep Learn-
ing Algorithms”.
Lung cancer presents a pervasive and life-threatening challenge, often identified at
advanced stages, thereby impeding treatment success rates and compromising patient
prognoses. The critical importance of early and accurate detection of lung cancer cannot
be overstated, as it holds the key to refining patient outcomes and potentially saving
lives. In this research endeavor, we embark on a comprehensive exploration of deep
learning techniques as a means of enhancing lung cancer detection. Our investigation
involves leveraging a rich dataset comprising diverse medical images, through which we
meticulously craft and refine deep convolutional neural networks (CNNs). These CNNs
are meticulously engineered to discern lung cancer lesions with heightened sensitivity and
specificity, aiming to overcome the limitations associated with late-stage diagnoses.

The results of our study unveil the transformative potential of deep learning in the
realm of early lung cancer detection, heralding a new era in clinical practice where timely
intervention becomes a tangible reality. By elucidating our methodology, presenting our
experimental findings, and discussing the implications of our research, we underscore the
profound impact that deep learning stands to make in the fields of medical imaging and
cancer diagnostics. This research not only sheds light on the promising strides made in
lung cancer detection but also serves as a beacon of hope for the future of patient care,
offering prospects for improved treatment outcomes and bolstered survival rates in the
battle against this formidable disease.

Dept. of ECE, JNNCE, Shimoga May-2024 8


2. Theoretical Background

[3] Diciotti S, Picozzi G, Falchini M, Mascalchi M, Villari N and Valli G.


proposed a “3-D segmentation algorithm of small lung nodules in spiral CT
images”.
Computed tomography (CT) stands out as the most sensitive imaging modality for
detecting lung nodules and is currently under evaluation as a screening tool for lung
cancer in various large-scale studies worldwide. This report delineates a semiautomatic
approach for 3-D segmentation of lung nodules in CT images, facilitating subsequent
volume assessment. The distinguishing features of our algorithm are twofold. Firstly, it
incorporates a user interaction process, enabling the incorporation of expert knowledge in
a straightforward and reproducible manner. Secondly, it adopts geodesic distance within
a multithreshold image representation, facilitating a fusion-segregation process based on
both gray-level similarity and object shape.

Validation of the algorithm was conducted on low-dose CT scans of small nodule


phantoms (with a mean diameter of 5.3-11 mm) and in vivo lung nodules (with a mean
diameter of 5-9.8 mm) detected in the Italung-CT screening program for lung cancer.
Further testing was performed on small lung nodules from the Lung Image Database
Consortium (LIDC) first data set. Results indicated a root mean square (RMS) error of
less than 6.6% in phantoms, with successful outlining of the nodule contour achieved in
82 out of 95 lung nodules in the Italung-CT dataset and in 10 out of 12 lung nodules
in the LIDC first data set. These findings underscore the viability of the proposed al-
gorithm for volume measurements of lung nodules assessed using low-dose CT scanning
techniques.

[4] Senthil Kumar K, Venkatalakshmi K and Karthikeyan K proposed


“Lung cancer detection using image segmentation by means of various evolu-
tionary algorithms. Computational and mathematical methods in medicine”.
The primary aim of this paper is to investigate an efficient image segmentation algorithm
for medical images, with the goal of reducing the burden on physicians in interpreting
computer tomography (CT) scan images. Given the complexity and size of modern medi-
cal images, manual analysis is arduous and time-consuming. The efficacy of segmentation
algorithms hinges on their accuracy and convergence time, prompting the need to ex-

Dept. of ECE, JNNCE, Shimoga May-2024 9


2. Theoretical Background

plore and implement new evolutionary algorithms to address the challenges associated
with medical image segmentation.

Lung cancer ranks as one of the most commonly diagnosed cancers worldwide, partic-
ularly among men, emphasizing the importance of early detection for timely treatment
and improved patient outcomes. CT imaging stands as a valuable tool in lung cancer
diagnosis. In this study, the performance of five optimization algorithms—k-means clus-
tering, k-median clustering, particle swarm optimization, inertia-weighted particle swarm
optimization, and guaranteed convergence particle swarm optimization (GCPSO)—is
evaluated for tumor extraction from lung images. Additionally, the effectiveness of me-
dian, adaptive median, and average filters in the preprocessing stage is compared, with
the adaptive median filter demonstrating superior suitability for medical CT images.
Furthermore, image contrast is enhanced through adaptive histogram equalization. The
preprocessed images of enhanced quality are then subjected to the four algorithms for
segmentation. Practical validation is conducted on 20 sample lung images using MAT-
LAB, revealing GCPSO to achieve the highest accuracy, at 95.89

[5] Chen L, Liu K, Shen H, Ye H, Liu H, Yu L, Li J, Zhao K and Zhu


W proposed a “Multimodality Attention-Guided 3-D Detection of Nonsmall
Cell Lung Cancer in 18 F-FDG PET/CT Images”.
In this article, we introduce a novel 3-D detection framework designed for identi-
fying nonsmall cell lung cancer (NSCLC) within 18 F-fluorodeoxyglucose (18 F-FDG)
positron emission tomography/computed tomography (PET/CT) images, guided by a
multimodality attention fusion approach. We amassed a dataset comprising 250 18 F-
FDG PET/CT scans from patients with histopathologically confirmed NSCLC, spanning
from January 1, 2015, to December 31, 2019. Our methodology revolves around a tailored
dual-path 3-D CenterNet for NSCLC detection, augmented by a novel multimodality at-
tention module aimed at adaptively refining multimodality feature map fusion.

Given the resource-intensive nature of 3-D convolutional neural networks (CNNs), ne-
cessitating ample graphic memory and sliding windows, we introduce a patch size strat-
egy for both training and testing phases. To evaluate our framework, we employ fivefold
cross-validation, yielding promising results. Notably, our proposed method achieves a

Dept. of ECE, JNNCE, Shimoga May-2024 10


2. Theoretical Background

sensitivity of 0.96 and a false positive per scan (FPPS) rate of 1.04, surpassing the per-
formance of the baseline 3-D CenterNet particularly in terms of sensitivity. Moreover, our
multimodality attention module exhibits potential applicability beyond NSCLC detec-
tion, showcasing competitive performance against other lung cancer detection methods.

Additionally, through comprehensive case studies, we demonstrate the efficacy of our


proposed method in detecting challenging-to-diagnose NSCLCs, underscoring its utility
for radiologists and medical physicists in clinical practice. Our findings underscore the
potential of our framework to enhance NSCLC diagnosis, potentially contributing to im-
proved patient care and outcomes in the field of oncology.

2.2 Conclusion of the literature


From the literature survey we have taken some important concepts which are been used
in our project, which includes the CNN architecture,CNN working with the given input
[Link] operation of the different types of kernel over the input [Link] study
underscores the pressing need for improved methods in lung cancer diagnosis, given its
dire prognosis and significant impact on patient outcomes. The conventional reliance on
manual interpretation of CT images for detecting lung cancer underscores the urgency for
more sophisticated approaches. The proposed CCDC-HNN [Link] the literature
survey has helped to acquire the knowledge about the CNN model in the detection of
cancer by using more effective methods in our project.

Dept. of ECE, JNNCE, Shimoga May-2024 11


Chapter 3

Design and Implementation

3.1 Introduction
The design and implementation of a detection and classification system for lung cancer
detection using Convolutional Neural Networks (CNN) involves several steps.

Figure 3.1: CNN Model

A CNN is a type of deep neural network that is designed to process and analyze the
data that has a grid-like topology, such as an image . As shown in the Figure 3.1, the
network consists of a series of convolutional layers that apply filters to the input data
followed by pooling layers that down sample the output which completes feature extrac-
tion. The final layers of the network typically include one or more fully connected layers
that perform classification.

Figure 3.2: Input data set(CT scan images).

Dept. of ECE, JNNCE, Shimoga May-2024 12


3. Design and Implementation

Input layer: This layer takes in the raw image data as input and prepares it for
processing by the rest of the network, that is the input layer would take in an image of
lungs CT scan. The input image can be represented as a 3D tensor of shape.

Convolutional 2D layer: This layerapplies a set of 32/64/128 filters of size 3*3 to


the dataset, which helps to extract features from the image. The resulting feature maps
highlight important patterns and edges in the image that can be used for classification.
The output of a convolutional layer can be computed using 3.1

a b c
!
X X X
h[i, j, k] = f kernel[l, m, n] · x[i + l, j + m, n] + bias[k] (3.1)
l=−a m=−b n=−c

Where, h[i,j,k] is the output activation at position (i,j) for the k-th filter, f is a non-
linear activation function, kernel[l,m,n] is the weight for the filter at position (l,m) and
channel n, x[i+l,j+m,n] is the pixel value at position (i+l,j+m) and channel n in the input
image, bias[k] bias term. Activation function rectified linear unit (ReLU): The output
of the convolutional layer is subjected to an activation function known as the ReLU layer.

2D layer (Max Pooling): This layer reduces the dimensionality of the feature maps
with 2*2 or 3*3 by down sampling using maximum.
Fully connected layer: This layer takes the flattened feature maps from the previous
layers and applies a set of weights and biases to produce an output which has been passed
through one or more fully connected layers that is hidden layers such as dense layer for
classification.
Output layer This layer produces the final output of the network, which is a probability
distribution over the different disease classes. The SoftMax function is applied to the
output to convert the probabilities into a probability distribution that sums to one. The
predicted class is the class with the highest probability in the output of the model.
This is the class that the model predicts the input image that it belongs to. After
designing the model, the dataset is divided into training, validation, and testing sets.
The training set is used to train the model, the validation set is used to tune the model’s
hyperparameters, and the testing set is used to evaluate the model’s performance. The
model is then trained using a suitable loss function, such as categorical cross-entropy,
and an optimization function, such as Adam. The model is trained for a certain number

Dept. of ECE, JNNCE, Shimoga May-2024 13


3. Design and Implementation

of epochs, and the model’s performance is monitored during training to detect overfitting
or underfitting. After training the model, the model’s performance is evaluated using the
testing set.

3.2 Block Diagram

Figure 3.3: Block Diagram

The block diagram you sent shows the process of classifying CT images. This is the
first step, where the CT image is uploaded into the system.

Input CT Image: This is the starting point, where the CT scan (computed tomogra-
phy) image is fed into the system.
Pre-processing: The CT image may undergo some preprocessing steps to enhance the
image quality and prepare it for further analysis. This may involve techniques like noise
reduction, contrast enhancement, or normalization.
[Link] Segmentation: In this stage, the relevant region of interest (ROI) is identified
and segmented from the background of the CT image. This ROI could be a specific organ
or tissue that the doctor is interested in examining.
[Link] Extraction: Key features are extracted from the segmented ROI, such as the

Dept. of ECE, JNNCE, Shimoga May-2024 14


3. Design and Implementation

edges of the lung including the all the non data part like rib-cages,blood-vessels etc,...
These features could be mathematical properties or characteristics of the image that can
be used to differentiate between normal and abnormal [Link] the preprocessing
stage is carried out in these mentioned steps:

1. Selected Image input

2. Gray scale image

3. Edge Detection

4. Threshold Detection

5. Image Sharpening (first instance)

6. Image Sharpening (second instance)

Figure 3.4: Preprocessing stages

[Link] Image input:The original CT scan image is [Link] image likely rep-
resents a cross-sectional view of the [Link] contains various structures, including bones,
organs, and lung tissue.
[Link] scale image:The selected image is converted into grayscale. Grayscale images
use intensity values (shades of gray) instead of color. This step simplifies the image and
helps focus on structural details.
[Link] Detection:Edges within the grayscale image are highlighted. Edge detection
algorithms identify abrupt changes in intensity (such as boundaries between different

Dept. of ECE, JNNCE, Shimoga May-2024 15


3. Design and Implementation

tissues). The goal is to outline structures like blood vessels, airways, and lung tissue.
[Link] Detection:A threshold value is applied to segment the image. Pixels with
intensity values above the threshold are considered part of the region of interest (ROI).
This step separates the lung tissue from the background.
[Link] Sharpening (first instance):The thresholded image is sharpened. Sharp-
ening enhances edges and fine details. It improves clarity and makes structures more
distinct.
[Link] Sharpening (second instance):The edge-detected image (from step 3) is
also sharpened. This further enhances the visibility of structures. Both the thresholded
and edge-detected versions benefit from sharpening.
In the final processed version, specific areas (likely representing lung tissue) are high-
lighted in green for easier identification.
Classification: Finally, a classification algorithm is applied to categorize the extracted
features and classify the image. The output could be a binary classification (normal vs.
abnormal) or a multi-class classification (different types of abnormalities).

3.3 Convolution operation over the input image

Figure 3.5: Convolution over the input image

The CNN applies a series of filters (kernels) to the input image. These filters slide over
the image, element-wise multiplying the corresponding pixels with the weights in the ker-
[Link] kernel slides over the input image, extracting features by performing element-wise
multiplication and summing the results. The purpose of the convolution is to extract
features from the image. In map creation, these features could be edges, lines, shapes, or
other patterns that might represent roads, buildings, or other features relevant to creat-
ing a [Link]: After the first convolution, there’s a step labeled “Pooling.” Pooling
reduces the spatial dimensions of the featured map by selecting the maximum or average

Dept. of ECE, JNNCE, Shimoga May-2024 16


3. Design and Implementation

value within a small window (e.g., 3x3). The result is a “Pooled Featured Map.”Second
Convolution: The process continues with another convolution step, resulting in a new
set of “Featured Maps.” Second Pooling: Finally, there’s another pooling step, creating
the “Pooled Featured Maps” after the second convolution. The overall process helps ex-
tract hierarchical features from the input image, making CNNs effective for classification,
affected area of lung’s detection, and segmentation.

3.4 Kernel function over Feature extraction

Figure 3.6: Diagram A to C is an example of convolution operation with a kernel size of


3x3,

Dept. of ECE, JNNCE, Shimoga May-2024 17


3. Design and Implementation

A kernel is applied across the input tensor, and an element-wise product between each
element of the kernel and the input tensor is calculated at each location and summed
to obtain the output value in the corresponding position of the output tensor, called a
feature [Link] process of training a CNN model with regard to the convolution layer is
to identify the kernels that work best for a given task based on a given training dataset.
Kernels are the only parameters automatically learned during the training process in the
convolution layer; on the other hand, the size of the kernels, number of kernels, padding,
and stride are hyper parameters that need to be set before the training process starts.
A set of 32/64/128 filters of size 3*3 to the dataset, which helps to extract features from
the image. The resulting feature maps highlight important patterns and edges in the
image that can be used for classification.

3.5 Description Of Libraries and Software


We have used different python libraries for various functions and description of each is
given below:
1. cv2 (OpenCV): OpenCV (Open Source Computer Vision Library) is an open-source
computer vision and machine learning software library widely used for image processing,
computer vision tasks, and real-time video analysis. Developed originally by Intel and
now maintained by the OpenCV community, OpenCV2 (often referred to as OpenCV)
offers a comprehensive suite of functions and algorithms that enable developers to per-
form a wide range of tasks, including image capture, manipulation, feature detection,
object recognition, and motion [Link] provides efficient functions for reading
CT scan images stored in various formats. It can also be used for essential preprocessing
tasks like resizing, normalization, and potentially intensity standardization of the images
for better model performance.

[Link] (np):NumPy excels at handling multidimensional arrays, which is crucial for


representing CT scan images. You can use NumPy for efficient image transformations,
calculations, and data restructuring for model [Link] provides various mathe-
matical functions that might be useful for calculations related to image processing or
model [Link] plays a crucial role in organizing and processing the data used
for training the machine learning model and managing the extracted features. Specif-

Dept. of ECE, JNNCE, Shimoga May-2024 18


3. Design and Implementation

ically, NumPy enables developers to store and manipulate the extracted features from
captured images.

3. os:This library allows you to interact with the operating system for tasks like access-
ing and managing CT scan image files. You can use it to navigate directories containing
the data and potentially define file paths for loading and saving [Link] offers function-
alities for checking file existence and handling potential errors during file access. This
can be useful for ensuring the code can gracefully handle situations where data files are
missing or [Link] libraries like cv2 are better suited for image loading itself,
os can indirectly aid in the process. By providing file paths and potentially listing files
within a directory, os can help prepare the groundwork for loading images using OpenCV
or other libraries.

4. random (shuffle):Shuffling the data before training helps prevent the model from
learning biases based on the order of data presentation. This is particularly important
for ensuring the model generalizes well to unseen data.

5. tqdm:Training a deep learning model on medical images can take time. Tqdm pro-
vides a progress bar that displays the training progress, making it easier to track the
ongoing process.

6. [Link] (ops):TensorFlow is an open-source machine


learning framework developed by Google, renowned for its flexibility, scalability, and ease
of use in building and deploying deep learning [Link] import statement suggests
using TensorFlow as the deep learning framework for building your lung cancer detection
model. TensorFlow provides the computational backend for defining and executing the
model’s [Link] operation is essential for CNNs used in image recognition tasks
like lung cancer detection. It performs the core convolution process described earlier,
where filters (kernels) slide across the input CT scan image, extracting features. [Link]
provides functions like [Link].conv2d to define convolutional layers in your model.

7. [Link]:Keras offers a high-level API for building deep learning


models. The Sequential class allows you to define a sequential model by stacking layers

Dept. of ECE, JNNCE, Shimoga May-2024 19


3. Design and Implementation

one after another. This is likely how you’ll construct your CNN architecture for lung
cancer classification.

8. [Link]:Dense layers are fully-connected layers commonly used in CNNs


for classification tasks. You’ll likely use a combination of convolutional layers for feature
extraction and dense layers at the end of your model for classifying CT scans as normal
or cancerous.

9. [Link]: Matplotlib can be used for visualizing CT scan images (poten-


tially for debugging purposes) and exploring the training process. You can use it to plot
training and validation loss/accuracy curves to monitor model performance. It offers a
comprehensive set of functions and tools for generating a wide range of plots, includ-
ing line plots, scatter plots, bar charts, histograms, heatmaps, and more. Matplotlib’s
seamless integration with other Python libraries, such as NumPy and Pandas, facilitates
efficient data manipulation and visualization workflows, enabling developers to generate
plots directly from data stored in arrays, dataframes, or other data structures.

3.6 Flow chart for training

Figure 3.7: Flow chart for training part of the project.

Dept. of ECE, JNNCE, Shimoga May-2024 20


3. Design and Implementation

[Link] Set:The process starts with a dataset. In the context of machine learning,
this dataset typically contains labeled [Link] row in the dataset represents an
instance (e.g., an image), and each column represents a feature.

[Link] Classification: The goal is to classify images into predefined categories or


classes. The “Image classification” diamond represents the task of assigning a label
(class) to an input image.

[Link] Representation: The matrix [1 0 0 0] ,[0 1 0 0] ,[0 0 1 0] ,[0 0 0 1] appears to


be an identity matrix. In the context of image classification, this matrix might represent
one-hot encoding for class labels. Each row corresponds to a class, and the diagonal
elements are 1 (indicating the presence of that class) while the off-diagonal elements are
0 (indicating absence).

[Link] Layers (Python Code Snippet):In context of our project the provided
Python code snippet appears to be related to creating training data. It defines two
functions: create-train-data() and process-test-data(). The create-train-data() function
reads images from different directories (presumably corresponding to different classes),
resizes them, and appends them to a training dataset. The process-test-data() function
processes test images similarly. The code snippet likely prepares data for training a CNN
model.

[Link] and Feature Extraction: The final diamond represents the training pro-
cess, where a machine learning model (possibly a CNN) is trained on the prepared data.
Feature extraction occurs within the convolutional layers of the model. The extracted
features are used for classification.

Dept. of ECE, JNNCE, Shimoga May-2024 21


3. Design and Implementation

3.7 Flow chart for the testing and validation part

Figure 3.8: flow chart for the testing of the unseen data

As explained in the above preprocessing steps in figure.3.4(preprocessing stages).the im-


age process starts with a dataset. In the context of machine learning, this dataset typi-
cally contains labeled examples.
[Link] Scale Image: The original color images are converted to grayscale. Grayscale
images have a single channel (intensity) instead of three (red, green, and blue).
[Link] Detection: Edge detection algorithms (such as Sobel or Canny) identify edges or
boundaries within the image. [Link] Detection: Thresholding converts grayscale
images into binary images by setting a threshold value. Pixels above the threshold be-
come white, and those below become black.
[Link] Sharpening: Sharpening enhances edges and details in the image.

Tumor Detection Decision: After preprocessing, the flowchart reaches a deci-


sion point labeled “Tumor Detected.” If the answer is “YES” the flow branches off into
different types of carcinomas: Adenocarcinoma Large Cell Carcinoma Squamous Cell
Carcinoma If the answer is “NO,” it simply leads to “Normal.”
Remedies: The “Remedies” section likely represents the next steps after tumor detec-

Dept. of ECE, JNNCE, Shimoga May-2024 22


3. Design and Implementation

tion. Unfortunately, the image doesn’t provide further details about the specific remedies
or treatment.

3.8 Summary
This project aims to develop a deep learning system for lung cancer detection and clas-
sification using CT scan images. The approach leverages convolutional neural networks
(CNNs) built with TensorFlow. CT scan data undergoes preprocessing steps like resizing
and normalization to prepare it for the model. TensorFlow serves as the computational
engine. The CNN extracts features from the CT scans using convolutional layers, which
identify relevant patterns in the images. Pooling layers then reduce the data dimen-
sionality while capturing the presence of these features. Activation functions introduce
non-linearity, allowing the model to learn complex relationships. Finally, fully-connected
layers classify the CT scan as normal or cancerous. By training the model with labeled
data, the system learns to differentiate between healthy and cancerous and also the type
of the cancer and aim to create a robust and efficient solution capable of accurately
identifying various types of lung cancer, including adenocarcinoma, squamous cell car-
cinoma,large cell carcinoma and normal one, based on the extracted features from CT
scans.

Dept. of ECE, JNNCE, Shimoga May-2024 23


Chapter 4

Results and Disscusion

The results of project are generalized in to three sections namely the collection of the
data samples for training the model,and preprocessing of the input ct scan image of the
lung cancer patient and at last the detection of the type of the lung cancer the input has
or normal [Link] additionally with the display of the remedies that should be taken for
a particular type of cancer detected

4.1 Data collection

Figure 4.1: Collection of Data set of different type of lung cancer

Dept. of ECE, JNNCE, Shimoga May-2024 24


4. Results and Disscusion

4.2 Preprocessing stages

Figure 4.2: Preprocessing views of the input

The above shown figure shows the preprocessing stages of the given input of an CT scan
image of the lung,which follows the different steps,the main aim is to make the data more
accurate for the prediction of the cancer from the given set of pre-trained values.

Figure 4.3: Graph of Accuracy and loss

Dept. of ECE, JNNCE, Shimoga May-2024 25


4. Results and Disscusion

4.3 Model training

Figure 4.4: lable name with different probability values

Figure 4.5: Model training values

Dept. of ECE, JNNCE, Shimoga May-2024 26


4. Results and Disscusion

4.4 Detection of lung cancer type and Remedies

Figure 4.6: Detection of the type of cancer and its remedies

Dept. of ECE, JNNCE, Shimoga May-2024 27


Chapter 5

Conclusion

Overall, this lung cancer detection project has the potential to make a significant con-
tribution to the fight against lung cancer. This project explored the potential of deep
learning for lung cancer detection and classification using CT scan images. A convo-
lutional neural network (CNN) architecture built with TensorFlow was implemented to
differentiate between normal lung tissue and various cancer types, including squamous cell
carcinoma, adenocarcinoma, and large cell carcinoma. The CNN successfully extracted
features from the CT scans using convolutional and pooling layers. Activation functions
introduced non-linearity, allowing the model to learn complex relationships between these
features. Finally, fully-connected layers classified the lung tissue. By training the model
with labeled data, the system achieved promising results in identifying and classifying
different lung cancer types. This approach holds promise for aiding medical professionals
in lung cancer diagnosis and potentially improving patient outcomes. However, further
research with larger datasets and validation on real-world clinical data is necessary to
ensure the model’s generalizability and clinical [Link] further research and
development, this technology could become a valuable tool for the detection of the lung
cancer. The proposed system with a accuracy of 93.89%. Consequently, this approach
helps in encouraging radiologists to engage in intelligent detection and giving them the
better remedial key notes to over come the disease.

Dept. of ECE, JNNCE, Shimoga May-2024 28


Appendix A

Appendix

A.1 Program for training the model


import cv2
import numpy as np
import os
from random import shuffle
from tqdm import tqdm
from [Link] import ops
from [Link] import Sequential
from [Link] import Dense
import [Link] as plt

TRAIN DIR = ’train’


TEST DIR = ’test’

IMG SIZE = 50
LR = 1e-3
MODEL NAME = ’[Link]’.format(LR, ’2conv-basic’)

def label img(img):


word label = img[0]
print(word label)

if word label == ’a’:


print(’Adenocarcinoma’)
return [1,0,0,0]

elif word label == ’b’:


print(’Large cell carcinoma’)

Dept. of ECE, JNNCE, Shimoga May-2024 29


A. Appendix

return [0,1,0,0]

elif word label == ’c’:


print(’Squamous cell carcinoma’)
return [0,0,1,0]

elif word label == ’d’:


print(’Normal’)
return [0,0,0,1]

def create train data():


training data = []
for img in tqdm([Link](TRAIN DIR)):
label = label img(img)

print(label)
path = [Link](TRAIN DIR,img)
img = [Link](path,[Link] COLOR)
img = [Link](img, (IMG SIZE,IMG SIZE))
training [Link]([[Link](img),[Link](label)])
shuffle(training data)
[Link](’train [Link]’, training data)
return training data

def process test data():


testing data = []
for img in tqdm([Link](TEST DIR)):
path = [Link](TEST DIR,img)
img num = [Link](’.’)[0]
img = [Link](path,[Link] COLOR)
img = [Link](img, (IMG SIZE,IMG SIZE))
testing [Link]([[Link](img), img num])

shuffle(testing data)
[Link](’test [Link]’, testing data)
return testing data

Dept. of ECE, JNNCE, Shimoga May-2024 30


A. Appendix

train data = create train data()

import tflearn
from [Link] import conv 2d, max pool 2d
from [Link] import input data, dropout, fully connected
from [Link] import regression
import tensorflow as tf
from [Link] import ops
[Link] default graph()

convnet = input data(shape=[None, IMG SIZE, IMG SIZE, 3], name=’input’)

convnet = conv 2d(convnet, 32, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 64, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 128, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 32, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 64, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = fully connected(convnet, 1024, activation=’relu’)


convnet = dropout(convnet, 0.8)

convnet = fully connected(convnet, 4, activation=’softmax’)


convnet = regression(convnet, optimizer=’adam’, learning rate=LR, loss=’categorical crossentropy’,
name=’targets’)

model = [Link](convnet, tensorboard dir=’log’)

Dept. of ECE, JNNCE, Shimoga May-2024 31


A. Appendix

if [Link](’.meta’.format(MODEL NAME)):
[Link](MODEL NAME)
print(’model loaded!’)

train = train data[:-16]


test = train data[-90:]

X = [Link]([i[0] for i in train]).reshape(-1,IMG SIZE,IMG SIZE,3)


Y = [i[1] for i in train]
print([Link])
test x = [Link]([i[0] for i in test]).reshape(-1,IMG SIZE,IMG SIZE,3)
test y = [i[1] for i in test]
print(test [Link])

history=[Link](’input’: X, ’targets’: Y,n epoch=100, validation set=(’input’: test x,


’targets’: test y),snapshot step=30, show metric=True, run id=MODEL NAME)

[Link](MODEL NAME)

A.2 Program for testing


import numpy as np /dealing with arrays
import os /dealing with directories
from random import shuffle / mixing up or currently ordered data that might lead our network
astray in training.
from tqdm import
tqdm /a nice pretty percentage bar for tasks. Thanks to viewer Daniel BA1/4hler for this
suggestion
import tflearn
from [Link] import conv 2d, max pool 2d
from [Link] import input data, dropout, fully connected
from [Link] import regression
import tensorflow as tf
import [Link] as plt
from flask import Flask, render template, url for, request

Dept. of ECE, JNNCE, Shimoga May-2024 32


A. Appendix

import sqlite3
import cv2
import shutil

connection = [Link](’user [Link]’)


cursor = [Link]()

command = ”””CREATE TABLE IF NOT EXISTS user(name TEXT, password TEXT,


mobile TEXT, email TEXT)”””
[Link](command)

app = Flask(name)
[Link](’/’)
def index():
return render template(’[Link]’)

[Link](’/userlog’, methods=[’GET’, ’POST’])


def userlog():
if [Link] == ’POST’:

connection = [Link](’user [Link]’)


cursor = [Link]()

name = [Link][’name’]
password = [Link][’password’]
query = ”SELECT name, password FROM user WHERE name = ’”+name+”’ AND pass-
word= ’”+password+”’”
[Link](query)

result = [Link]()

if len(result) == 0:
return render template(’[Link]’, msg=’Sorry, Incorrect Credentials Provided, Try Again’)
else:
return render template(’[Link]’)

Dept. of ECE, JNNCE, Shimoga May-2024 33


A. Appendix

return render template(’[Link]’)


[Link](’/userreg’, methods=[’GET’, ’POST’])
def userreg():
if [Link] == ’POST’:

connection = [Link](’user [Link]’)


cursor = [Link]()

name = [Link][’name’]
password = [Link][’password’]
mobile = [Link][’phone’]
email = [Link][’email’]

print(name, mobile, email, password)


command = ”””CREATE TABLE IF NOT EXISTS user(name TEXT, password TEXT, mo-
bile TEXT, email TEXT)”””
[Link](command)

[Link](”INSERT INTO user VALUES (’”+name+”’, ’”+password+”’, ’”+mobile+”’,


’”+email+”’)”)
[Link]()

return render template(’[Link]’, msg=’Successfully Registered’)

return render template(’[Link]’)


[Link](’/[Link]’)
def demo():
return render template(’[Link]’)

[Link](’/image’, methods=[’GET’, ’POST’])


def image():
if [Link] == ’POST’:

dirPath = ”static/images”
fileList = [Link](dirPath)
for fileName in fileList:

Dept. of ECE, JNNCE, Shimoga May-2024 34


A. Appendix

[Link](dirPath + ”/” + fileName)


fileName=[Link][’filename’]
dst = ”static/images”
[Link](”test/”+fileName, dst)
image = [Link](”test/”+fileName)
color conversion
gray image = [Link](image, [Link] BGR2GRAY)
[Link](’static/[Link]’, gray image)
/apply the Canny edge detection
edges = [Link](image, 100, 200)
[Link](’static/[Link]’, edges)
apply thresholding to segment the image
retval2,threshold2 = [Link](gray image,128,255,[Link] BINARY)
[Link](’static/[Link]’, threshold2)
/ create the sharpening kernel
kernel sharpening = [Link]([[-1,-1,-1], [-1, 9,-1], [-1,-1,-1]])

sharpened = cv2.filter2D(image, -1, kernel sharpening)

/ save the sharpened image


[Link](’static/[Link]’, sharpened)
def segment tumor(image, lower gray threshold, upper white threshold, pixel to mm conversion):
/ Read the input image
image = [Link](image, [Link] GRAYSCALE)

/Thresholding to segment the tumor


mask = [Link](image, lower gray threshold, upper white threshold)
/Find contours in the binary image
contours, = [Link](mask, [Link] EXTERNAL, [Link] APPROX SIMPLE)

/Create a mask for the tumor area


tumor mask = [Link] like(image)
[Link](tumor mask, contours, -1, (255, 255, 255), thickness=[Link])

/Overlay the tumor mask on the original image


tumor area image = [Link](image, [Link] GRAY2BGR)

Dept. of ECE, JNNCE, Shimoga May-2024 35


A. Appendix

tumor area image[tumor mask == 255] = [0, 255, 0] / Mark tumor area in green
Calculate area of the tumor
tumor area pixel = sum([Link](contour) for contour in contours)
tumor area mm = tumor area pixel * pixel to mm conversion ** 2

/ Calculate the diameter of the tumor


, radius = [Link](max(contours, key=[Link])) tumor diameter pixel
= 2 * radius tumor diameter mm = tumor diameter pixel * pixel to mm conversion
return tumor area mm, tumor diameter mm, tumor area image
Example usage
image path = ”[Link]” Replace with the actual image path

/Adjust these threshold values based on the characteristics of your image


lower gray threshold = 150
upper white threshold = 200

/Pixel to millimeter conversion factor


pixel to mm conversion = 0.1 Example conversion factor, adjust according to your image

tumor area mm, tumor diameter mm, tumor area image = segment tumor(gray image, lower gray thres
upper white threshold, pixel to mm conversion)
print(”Area of Tumor:”, tumor area mm, ”mm”)
print(”Diameter of Tumor:”, tumor diameter mm, ”mm”)
[Link](’static/[Link]’,tumor area image)

verify dir = ’static/images’


IMG SIZE = 50
LR = 1e-3
MODEL NAME = ’[Link]’.format(LR, ’2conv-basic’)
MODEL NAME=’keras model.h5’
def process verify data():
verifying data = []
for img in [Link](verify dir):
path = [Link](verify dir, img)
img num = [Link](’.’)[0]
img = [Link](path, [Link] COLOR)

Dept. of ECE, JNNCE, Shimoga May-2024 36


A. Appendix

img = [Link](img, (IMG SIZE, IMG SIZE))


verifying [Link]([[Link](img), img num])
[Link](’verify [Link]’, verifying data)
return verifying data

verify data = process verify data()


verify data = [Link](’verify [Link]’)

[Link] default graph()


[Link] default graph()

convnet = input data(shape=[None, IMG SIZE, IMG SIZE, 3], name=’input’)

convnet = conv 2d(convnet, 32, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 64, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 128, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 32, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = conv 2d(convnet, 64, 3, activation=’relu’)


convnet = max pool 2d(convnet, 3)

convnet = fully connected(convnet, 1024, activation=’relu’)


convnet = dropout(convnet, 0.8)

convnet = fully connected(convnet, 4, activation=’softmax’)


convnet = regression(convnet, optimizer=’adam’, learning rate=LR, loss=’categorical crossentropy’,
name=’targets’)

model = [Link](convnet, tensorboard dir=’log’)

Dept. of ECE, JNNCE, Shimoga May-2024 37


A. Appendix

if [Link](’.meta’.format(MODEL NAME)):
[Link](MODEL NAME)
print(’model loaded!’)

fig = [Link]()

str label=” ”
accuracy=””
rem=””
rem1=””
for num, data in enumerate(verify data):

img num = data[1]


img data = data[0]

y = [Link] subplot(3, 4, num + 1)


orig = img data
data = img [Link](IMG SIZE, IMG SIZE, 3)
model out = [Link]([data])[0]
model out = [Link]([data])[0]
print(model out)
print(’model ’.format([Link](model out)))

if [Link](model out) == 0:
str label = ”Adenocarcinoma”
print(”The predicted image of the Adenocarcinoma is with a accuracy of ”.format(model out[0]∗100))
accuracy=”The predicted image of the Adenocarcinoma is with a accuracy of”.format(model out[0]∗100)
rem = ”The treatment for Adenocarcinoma are: ”
rem1 = [”Surgery: Often the primary treatment for early-stage cancer to remove the tumor.”,
”Chemotherapy: Used to kill cancer cells and shrink tumors, sometimes before or after surgery.”,
”Radiation therapy: Targets cancer cells.”,
”Targeted therapy: Addresses specific mutations.”,
”Immunotherapy: Boosts the immune system.”,
”Individualized treatment plans.”,
”Collaboration with healthcare team crucial.”]

Dept. of ECE, JNNCE, Shimoga May-2024 38


A. Appendix

elif [Link](model out) == 1:


str label = ”Large cell carcinoma”
print(”The predicted image of the Large cell carcinoma is with a accuracy of ”.format(model out[1]∗100))
accuracy=”The predicted image of the Large cell carcinoma is with a accuracy of ”.format(model out[1]∗100)
rem = ”The treatment for Large cell carcinoma are: ”
rem1 = [”Surgery: Often the primary treatment if the cancer is localized.”,
”Chemotherapy: Used to kill cancer cells and shrink tumors, sometimes given before surgery
(neoadjuvant) or after surgery (adjuvant).”,
”Radiation therapy: May be used alongside surgery or chemotherapy to target cancer cells.”,
”Targeted therapy: Drugs that target specific mutations or proteins in cancer cells, if applica-
ble.”,
”Immunotherapy: Boosts the body’s immune system to fight cancer cells.”]

elif [Link](model out) == 2:


str label = ”Squamous cell carcinoma”
print(”The predicted image of the Squamous cell carcinoma is with a accuracy of
”.format(model out[2]*100))
accuracy=”The predicted image of the Squamous cell carcinoma is with a accuracy of
”.format(model out[2]*100)
rem = ”The treatment for Squamous cell carcinoma are: ”
rem1 = [”Surgery: Primary treatment for localized cancer, aims to remove the tumor.”,
”Radiation therapy: Often used in combination with surgery or alone for inoperable tumors.”,
”Chemotherapy: Sometimes used alongside surgery or radiation to kill cancer cells.”,
”Targeted therapy: Drugs targeting specific mutations, although less common compared to
other lung cancer types.”,
”Immunotherapy: Increasingly used, especially for advanced or metastatic cases, to boost the
immune system’s ability to fight cancer.”,
”Treatment plan tailored to individual patients based on cancer stage, overall health, and spe-
cific characteristics of the tumor.”,
”Close collaboration with healthcare team is crucial for determining the best treatment ap-
proach and managing side effects.”]

elif [Link](model out) == 3:


str label = ”Normal”
print(”The predicted image of the Normal is with a accuracy of ”.format(model out[3]∗100))

Dept. of ECE, JNNCE, Shimoga May-2024 39


A. Appendix

accuracy=”The predicted image of the Normal is with a accuracy of ”.format(model out[3]∗100)

area count = [”:.2f”.format(tumor area mm), ”:.2f”.format(tumor diameter mm),tumor area image]
/Result
print(f”Area of Tumor: tumor area mm:.2f”,”mm”)
print(f”Diameter of Tumor: tumor diameter mm:.2f”,”mm”)

return render template(’[Link]’,


status=str label,accuracy=accuracy,area count=area count,treatment=rem,treatment1=rem1,ImageDisplay

return render template(’[Link]’)

@[Link](’/logout’)
def logout():
return render template(’[Link]’)

if name == ”main”:
[Link](debug=True)

Dept. of ECE, JNNCE, Shimoga May-2024 40


References

[1] S. Wankhade and S. Vigneshwari, “A novel hybrid deep learning method for early de-
tection of lung cancer using neural networks,” Healthcare Analytics, vol. 3, p. 100195,
2023.

[2] S. Shashikala, N. Parveen, A. Maqbool, H. Khan, S. K. Alghadeer, and G. Singh,


“A novel approach for lung cancer detection using deep learning algorithms,” Inter-
national Journal of Intelligent Systems and Applications in Engineering, vol. 12, no.
15s, pp. 471–480, 2024.

[3] S. Diciotti, G. Picozzi, M. Falchini, M. Mascalchi, N. Villari, and G. Valli, “3-d


segmentation algorithm of small lung nodules in spiral ct images,” IEEE transactions
on Information Technology in Biomedicine, vol. 12, no. 1, pp. 7–19, 2008.

[4] K. Senthil Kumar, K. Venkatalakshmi, K. Karthikeyan et al., “Lung cancer detection


using image segmentation by means of various evolutionary algorithms,” Computa-
tional and mathematical methods in medicine, vol. 2019, 2019.

[5] L. Chen, K. Liu, H. Shen, H. Ye, H. Liu, L. Yu, J. Li, K. Zhao, and W. Zhu,
“Multimodality attention-guided 3-d detection of nonsmall cell lung cancer in 18 f-
fdg pet/ct images,” IEEE Transactions on Radiation and Plasma Medical Sciences,
vol. 6, no. 4, pp. 421–432, 2021.

Dept. of ECE, JNNCE, Shimoga May-2024 41

You might also like