0% found this document useful (0 votes)
72 views

Lecture - 4 Medical Image Analysis

1. Image thresholding uses histograms to convert images to binary by separating pixel intensities into foreground and background. 2. Global thresholding uses a single threshold value for the entire image while local thresholding calculates individual thresholds for image regions. 3. Otsu's method automatically determines an optimal global threshold by maximizing between-class variance. Adaptive thresholding determines thresholds based on local image areas.

Uploaded by

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

Lecture - 4 Medical Image Analysis

1. Image thresholding uses histograms to convert images to binary by separating pixel intensities into foreground and background. 2. Global thresholding uses a single threshold value for the entire image while local thresholding calculates individual thresholds for image regions. 3. Otsu's method automatically determines an optimal global threshold by maximizing between-class variance. Adaptive thresholding determines thresholds based on local image areas.

Uploaded by

ahsan puri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

MEDICAL IMAGE

ANALYSIS
DR. ZOBIA SUHAIL
PHD IN MEDICAL IMAGE PROCESSING
A B E R Y S T W Y T H U N I V E R S I T Y, WA L E S , U K ( 2 0 1 9 )
MEDICAL IMAGE ANALYSIS

Overview of Previous Lecture:

• Course overview
• Python Introduction using common libraries
• How to read and analyze image in Python
• Image Intensities
• Difference in intensity levels for Grayscale and Color images
• Image Histograms
• Some Discussion on the Application areas of Image Histograms
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:

An image histogram can be used to threshold the image to convert it into binary image.

If the image intensities are well separated into two defined objects, the histogram is well
Suited to define the threshold of the image.

The histogram will be bi-modal and the pixel intensities can be separated into two well
Defined groups.
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:

Image Source: Optimal Threshold Computing in Automatic Image Thresholding using Adaptive Particle Swarm Optimization
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:

If T is the obtained threshold, then the image can be binarized using the following relation:

For all pixel p in image I:


If p >= T:
p =0
Else
p =1
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Import cv2 as cv
Import imageio as io
Im=io.imread(‘original.png’)
thresh=190
r,c=m_img.shape
i=0
j=0
new_im=np.zeros((r,c),dtype=np.uint8)
for i in range(r):
for j in range(c):
if(m_img[i,j]>=thresh):
new_im[i,j]=1
else:
new_im[i,j]=0
plt.imshow(new_im,cmap="gray")
plt.show()
plt.close()
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Discussion:
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType)
Ret,thresh=cv2.threshold(im,120,256,cv2.Threshold_Binary)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType)
cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
cv2.THRESH_TRUNC
cv2.THRESH_TOZERO
cv2.THRESH_TOZERO_INV
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:

Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType)

cv2.THRESH_BINARY
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType)

cv2.THRESH_BINARY_INV
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType

cv2.THRESH_TRUNC
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType

cv2.THRESH_TOZERO
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:
PYTHON

Thresholding using Pyhton libraries:


Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType

cv2.THRESH_TOZERO_INV
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:
Cv2 library in Python for Thresholding

Cv2.threshold
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:
Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv.threshold(im1,190,255,cv.THRESH_BINARY)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:

Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv.threshold(im1,190,255,cv.THRESH_BINARY_INV)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:
Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv.threshold(im1,190,255,cv.THRESH_TRUNC)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:

Cv2 library in Python for Thresholding

Cv2.threshold

Ret,dest=cv.threshold(im1,190,255,cv.THRESH_TOZERO)
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]

PYTHON
Thresholding using Python libraries:

Cv2 library in Python for Thresholding

Cv2.threshold
Import cv2 as cv

Thresh=190
Ret,dest=cv.threshold(im,thresh,255,cv.THRESH_TOZERO_INV)
plt.imshow(dest,cmap="gray")
plt.show()
plt.close()
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:

The thresholds that we used so far are arbitrary chosen threshold values , that is not a good choice.

Our algorithm should be able to find the optimum threshold value……


[REASEARCH POINT]

Otsu method determines the threshold value of the image automatically.

We just need to pass an extra argument to cv.threshold function

Ret, dest=cv2.threshold(im,thresh,max_value,cv2.ThresholdType+cv2.Thresh_Otsu)

Ret is the optimum threshold value calculated using Otsu method.


MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
PYTHON

Applications of Histograms: [Image Thresholding + OTSU Method]


Python:
Import cv2 as cv
Import imageio as io
Io.imread(‘original.png’)
Ret,dest=cv.threshold(im,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
plt.imshow(dest,cmap="gray")
plt.show()
plt.close()

Discussion:
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding: [Otsu Method ---- Continued ]

Otsu Method maximized the between class variance……

Otsu method iterate through all possible threshold values

And find the spread of pixels on each side of the threshold i.e. for foreground and for background.

Select that particular intensity as threshold value having minimum foreground


And background spread i.e minimize the within class variance.
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding:

The techniques that we studies so far are Global Thresholding


i.e. it selects only one value for the whole image.

Problem: What is different section of the image has variation in


lighting.?

Global Thresholding is not appropriate solution:

Adaptive thresholding is a better solution in that case.


The algorithm determines the threshold of a pixel based
On the surrounding region.
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
 Thresholding [Local Thresholding]:

Different options are available for adaptive thresholding

• Grid of Cells

• Statistically measurement of intensity values of the


Local neighbourhood for each pixel.

python --- CV2.adaptivehreshold


MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
Applications of Histograms: [Local Thresholding]

local threshold is determined at each pixel


by the local average around the pixel.

Image Courtesy: https://www.researchgate.net/figure/Binarization-by-global-thresholding-and-local-thresholding-For-this-input-image-no_fig3_236125496


MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
PYTHON
 Thresholding [Local Thresholding]:

Applications of Histograms: [Adaptive Thresholding]

Dest = cv.adaptiveThreshold (src, maxValue, adaptiveMethod, thresholdType, blockSize, C)


MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
PYTHON
 Thresholding [Local Thresholding]:

Applications of Histograms: [Adaptive Thresholding]

Adaptive Method - It decides how thresholding value is calculated

cv2.ADAPTIVE_THRESH_MEAN_C : threshold value is the mean of neighbourhood area.

cv2.ADAPTIVE_THRESH_GAUSSIAN_C : threshold value is the weighted sum of neighbourhood values where


weights are a gaussian window.
MEDICAL IMAGE ANALYSIS
Histogram: [Applications]
PYTHON
 Thresholding [Local Thresholding]:

Applications of Histograms: [Adaptive Thresholding]

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

img = cv.imread('original.png',0)

ret,im1 = cv.threshold(img,180,255,cv.THRESH_BINARY)
im2 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY,11,2)

plt.imshow(im1,cmap="gray")
plt.show()
plt.close()

plt.imshow(im2,cmap="gray")
plt.show()
plt.close()

Discussion:
MEDICAL IMAGE ANALYSIS
Applications of Histograms: [Image Enhancement - Histogram Equalization ]

Improve the image contrast [Histogram Equalization]

Enhance the image by spreading the most frequent Intensity values.

Image Courtesy: Wikipedia


MEDICAL IMAGE ANALYSIS
Applications of Histograms: [Image Enhancement - Histogram Equalization ]

Original Image

Enhanced Image
MEDICAL IMAGE ANALYSIS
Image Enhancement:

Improve the image contrast [Histogram Equalization]

Enhance the image by spreading the most frequent Intensity values.

CV2.EQUALIZEHIST(IMG)

Steps:
1. Calculate the frequency against each intensity value
2. Compute the probability of each frequency
3. Compute Cumulative Distribution Function (CDF)
4. Multiple the CDF with the required intensity levels
5. Round the resultant value to Floor
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice:

3 2 4 5
7 7 8 2
Suppose this matrix is representing pixel intensities.
3 1 2 3
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice:

3 2 4 5
7 7 8 2 Intensity if Pixels range between 1 – 8
3 1 2 3 Suppose we want to apply histogram equalization
5 4 6 7 And scale the intensity to 1 - 20
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 1

3 2 4 5 Count the total number of pixels belongs to each


Intensity.
7 7 8 2
3 1 2 3
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 1

3 2 4 5
7 7 8 2 Pixel 1 2 3 4 5 6 7 8
Intensities
3 1 2 3
No. of Pixels 1 3 3 2 2 1 3 1
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 2

3 2 4 5 Find the probability of each pixel intensity.


7 7 8 2
3 1 2 3
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 2

3 2 4 5 Find the probability of each pixel intensity.


7 7 8 2
Total number of elements are 16.
3 1 2 3
5 4 6 7 Probability = No. of pixels associated to a particular intensity

Total number of elements (i.e. 16)


MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 2

3 2 4 5 Pixel Intensities 1 2 3 4 5 6 7 8
7 7 8 2 No. of Pixels 1 3 3 2 2 1 3 1
3 1 2 3 Probability .625 .1875 .1875 .125 .125 .0625 .1875 .0625

5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 3

3 2 4 5
7 7 8 2
Next step is to compute the cumulative probability
3 1 2 3
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 3

Pixel Intensities 1 2 3 4 5 6 7 8
No. of Pixels 1 3 3 2 2 1 3 1
Probability .0625 .1875 .1875 .125 .125 .0625 .1875 .0625

Cumulative .0625 .25 .4375 .5625 .6875 .75 .9375 1


Probability
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 4

3 2 4 5
7 7 8 2
As we want to increase the intensity to the reange1 -20,
3 1 2 3
5 4 6 7 Multiply each Cumulative Probability by 20
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 4

Pixel Intensities 1 2 3 4 5 6 7 8
No. of Pixels 1 3 3 2 2 1 3 1
Probability .0625 .1875 .1875 .125 .125 .0625 .1875 .0625

Cumulative .0625 .25 .4375 .5625 .6875 .75 .9375 1


Probability
C.P x 20 1.25 5 8.75 11.25 13.75 15 18.75 20
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 5

3 2 4 5
7 7 8 2
Last step in to round the decimal values (floor rounding)
3 1 2 3
5 4 6 7
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Step 5
Pixel Intensities 1 2 3 4 5 6 7 8
No. of Pixels 1 3 3 2 2 1 3 1
Probability .625 .1875 .1875 .125 .125 .0625 .1875 .0625

Cumulative .625 .25 .4375 .5625 .6875 .75 .9375 1


Probability
C.P x 20 1.25 5 8.75 11.25 13.75 15 18.75 20

Floor Rounding 1 5 8 11 13 15 18 20
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]


Practice: Final Result

3 2 4 5 8 5 11 13
7 7 8 2 18 18 20 5
3 1 2 3 8 1 5 8
5 4 6 7 13 11 15 18

Original Image has been transformed to equalized image with different intensities
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]

Histogram Equalization in Python:

CV2.equalizeHist(IMG)

Discussion:
MEDICAL IMAGE ANALYSIS

Applications of Histograms: [Image Enhancement - Histogram Equalization ]

Histogram Equalization in Python:

import cv2 as cv

im1=cv.imread('original.png',0)

equ_img= cv.equalizeHist(im1)
cv.imshow('Binary Image', equ_img)
cv.waitKey(0)
cv.destroyAllWindows()

Discussion:
MEDICAL IMAGE ANALYSIS

Normal Distribution / Gaussian Distribution:

Image Courtesy: https://statisticsbyjim.com/basics/normal-distribution/


MEDICAL IMAGE ANALYSIS

End of Lecture _4_5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy