Experiment No.4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Experiment No: 4

Title: Apply different thresholds &filter using MATLAB and DIPLAB- 1.0

Software Used:
Programming Language – MATLAB® (Version 7 or higher), VisualDSP++
Operating System – Microsoft Windows (XP 32-bit or higher)(Preferable)

Theory:

Thresholding
If in original contrast stretching function r1=r2=th, s1=00 and s2=L-1, the
transformation function becomes a thresholding function, that creates a binary
image. This function is shown as below.

Fig. Thresholding mapping transform function

In computer vision and image processing. Otsu's method is used to


automatically perform clustering-based image thresholding, or, the reduction of
a grayscale image to a binary image. The algorithm assumes that the image
contains two classes of pixels following bi-modal histogram (foreground pixels
and background pixels), it then calculates the optimum threshold separating the
two classes so that their combined spread (intra-class variance) is minimal. The
extension of the original method to multi-level thresholding is referred to as the
Multi Otsu method.

Median Filter

Median filtering is a nonlinear method used to remove noise from images.


It is widely used as it is very effective at removing noise while preserving
edges. It is particularly effective at removing ‘salt and pepper’ type noise.
The median filter works by moving through the image pixel by pixel,
replacing each value with the median value of neighbouring pixels. The pattern
of neighbours is called the "window", which slides, pixel by pixel, over the
entire image. The median is calculated by first sorting all the pixel values from
the window into numerical order, and then replacing the pixel being considered
with the middle (median) pixel value.

Procedure:
Using MATLAB
1. Open an image using ‘imread’ and ‘imshow’ functions. Convert it to
grayscale if required.
2. For Global Single thresholding (Manual), choose a threshold value‘t’.
Obtain the image segmentation result by using "im2bw function using 't’.
Display the result.
3. For Global Dual thresholding (Manual), choose two threshold values "t1"
and "t2".Obtain the image segmentation result by designing an algorithm
using conditional statements. Display the result.
4. For Global Single thresholding (Automated), use function 'graythresh' to
obtain the threshold value‘t’ automatically by Otsu's method. Obtain the
image segmentation result by using ‘im2bw’ function using‘t’. Display
the result.

Using DIPLAB
1. Load the image in processor memory
2. Note down the height and width of image which is loaded.
3. Replace the value of variable iImgWdt and iImgHgt with image width
and height
4. Compile the program
5. Run the program with multi-processor Run Mode
6. Read the output image from the processor memory defined in the
program

Conclusion:

You might also like