SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
PENNSYLVANIASTATE UNIVERSITY
Digital Image
Processing Project 2
Using median filter theory to create a similar function
Chad RyanWeiss
3/8/2016
Abstract:
This report contains information on median filter theory as well as some of the basic
MatLab functions and code (written by author) that demonstrates the practicality of such a
digital image processing filter.
Theory:
Median filtering is a common filtering technique used in digital image processing, often
used to eliminate unwanted noise in any given image. This type of filter works best for
removing salt & pepper noise (which basically consists of black and white specks appearing
throughout the image).
To operate, the filter must:
 Create a square, odd-numbered matrix (mask or window).
 Fill the mask with the values from the original noisy image.
 Calculate the median value of the mask.
 Replace the centermost cell of the mask with the median.
 Proceed to the next row or column and repeat.
Figure 1: Median Filtering
If you refer to Fig. 1 shown above, you will notice that we begin with an image, an intensity
matrix consisting of rows and columns each filled with pixel values used to designate the
strength or magnitude of the color of the cell (top). Next you will see the mask, which is a
square, three-by-three dimensional matrix that has focused itself upon one particular area
within the image (center). The mask captures the values of the image and sorts them in
ascending order into a data array, which can then be used to determine the median value of
the mask (bottom). Once that has been completed, the median value will replace the center
value of the mask which will imprint itself upon the original image thus completing the
cycle. It will shift and repeat the same process until the entire image has been filtered.
This is how the median filter operates.
MatLab:
The code below shows a MatLab based computer program used to median filter a RGB
color image. It takes no more than 180 seconds to filter a 1045-by-585-by-3 dimensional
image.
% Name: Chad Weiss
% Date: March 8, 2016
% Instructor: Dr. Morales
% Program: This program is a median filter
clear all
% Image
I = imread('Focus.jpg');
Status = imfinfo('Focus.jpg');
% Noisy Image
J = imnoise(I, 'salt & pepper', 0.1);
figure; imshow(J); title('Noisy Image');
% Image Conversions
Jhsv = rgb2hsv(J);
Jhsv0 = [zeros(1,Status.Width,3);Jhsv;zeros(1,Status.Width,3)];
Jhsv0 = [zeros(Status.Height+2,1,3),Jhsv0,zeros(Status.Height+2,1,3)];
Jh = Jhsv0(:,:,1);
Js = Jhsv0(:,:,2);
Jv = Jhsv0(:,:,3);
% Apply Filter
for i = 1:Status.Height
for j = 1:Status.Width
mask = Jh(i:i+2,j:j+2);
med = median(sort(transpose(single(mask(1:9)))));
Jh(i+1,j+1) = med;
end
end
% Apply Filter
for i = 1:Status.Height
for j = 1:Status.Width
mask = Js(i:i+2,j:j+2);
med = median(sort(transpose(single(mask(1:9)))));
Js(i+1,j+1) = med;
end
end
% Apply Filter
for i = 1:Status.Height
for j = 1:Status.Width
mask = Jv(i:i+2,j:j+2);
med = median(sort(transpose(single(mask(1:9)))));
Jv(i+1,j+1) = med;
end
end
F = hsv2rgb(cat(3,Jh,Js,Jv));
figure; imshow(F); title('Filtered Image');
You can see the results on the following page.
Figure 2: Noisy Image
Figure 3: Filtered Image (using Median Filtering)
The code used above was written by the author of this report. There are functions in
MatLab that perform similar operations such as the medfilt2 function. See the code
below for a demonstration of this function.
clear all
% Image
I = imread('Focus.jpg');
Status = imfinfo('Focus.jpg');
% Noisy Image
J = imnoise(I, 'salt & pepper', 0.1);
figure; imshow(J); title('Noisy Image');
% Image Conversions
Jhsv = rgb2hsv(J);
Jhsv0 = [zeros(1,Status.Width,3);Jhsv;zeros(1,Status.Width,3)];
Jhsv0 = [zeros(Status.Height+2,1,3),Jhsv0,zeros(Status.Height+2,1,3)];
Jh = Jhsv0(:,:,1); Js = Jhsv0(:,:,2); Jv = Jhsv0(:,:,3);
% Apply Filters
Ih = medfilt2(Jh); Is = medfilt2(Js); Iv = medfilt2(Jv);
% Image Conversions
output = hsv2rgb(cat(3, Ih,Is,Iv));
% Display Image
figure; imshow(output); title('Filtered Image');
You can see that the image has been filtered from the original in Fig. 2; however, Fig. 3
appears to have a much better filter than Fig. 4.
Figure 4: Filtered Image (using medfilt2)
Analysis/Observations:
Upon coding the filter, it was noticed that the filtering techniques (both MatLab’s and the
author’s) were ineffective against three dimensional images; i.e., images including height,
width and depth, suggesting multiple planes. To overcome this challenge it was necessary
to convert the RGB (Red, Green, Blue) image into HSV (Hue, Saturation, Value) format;
furthermore, it was necessary to create variables holding the individual planes H, S and V,
for they are only two dimensional images containing height and width. After isolating the
planes, it was possible to apply the filters individually (to H, S and V), eliminating any
unwanted noise. Lastly, to recombine the three, two-dimensional filtered images into a
three-dimensional filtered image, we simply concatenated the three planes and converted
it back to RGB format.
Conclusion:
In conclusion, the hand-written median filter took about three minutes to run. In
comparison, the pre-installed, built-in MatLab functions took only about three seconds to
run; however, the quality of the image is much better the first time around for the hand-
written version. For an explanation of the code, please refer to Appendix A.
Appendix A: Code
Variables
If you refer to Fig. 5, you will see the list of variables used
in running the median filter computer program.
I: This variable contains the original image.
J: This variable contains the noisy image.
Figure 5: List of Variables
Jhsv: This variable contains the hsv noisy image.
Jhsv0: This variable contains the hsv noisy image w/ a zero border (1 pixel black border).
Jh: This variable contains the h-plane image of the Jhsv0 image.
Js: This variable contains the s-plane image of the Jhsv0 image.
Jv: This variable contains the v-plane image of the Jhsv0 image.
Status: This variable contains the original image I information.
mask: This variable is the 3x3x3 dimensional mask used in filtering the noisy images.
med: This variable contains the median value of the mask.
i: This is a row counter variable.
j: This is a column counter variable.
F: This variable contains the filtered image.
Functions:
imread(_): Reads-in an image
imfinfo(_): Reads-in image information
imshow(_): Displays an image
imnoise(_): Adds noise to an image
rgb2hsv(_): Converts a RGB image to HSV format
hsv2rgb(_): Converts a HSV image to RGB format
single(_): Converts data to the datatype single
transpose(_): Transposes matrices
sort(_): Sorts any matrix or array in ascending order
median(_): Determines the median value of any matrix or array
cat(_): Concatenates arrays
help: See above

Weitere ähnliche Inhalte

Was ist angesagt?

JonathanWestlake_ComputerVision_Project2
JonathanWestlake_ComputerVision_Project2JonathanWestlake_ComputerVision_Project2
JonathanWestlake_ComputerVision_Project2Jonathan Westlake
 
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAIN
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAINIMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAIN
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAINijma
 
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...CSCJournals
 
A proposed accelerated image copy-move forgery detection-vcip2014
A proposed accelerated image copy-move forgery detection-vcip2014A proposed accelerated image copy-move forgery detection-vcip2014
A proposed accelerated image copy-move forgery detection-vcip2014SondosFadl
 
FAN search for image copy-move forgery-amalta 2014
 FAN search for image copy-move forgery-amalta 2014 FAN search for image copy-move forgery-amalta 2014
FAN search for image copy-move forgery-amalta 2014SondosFadl
 
Image Degradation & Resoration
Image Degradation & ResorationImage Degradation & Resoration
Image Degradation & ResorationSanjay Saha
 
An efficient approach to wavelet image Denoising
An efficient approach to wavelet image DenoisingAn efficient approach to wavelet image Denoising
An efficient approach to wavelet image Denoisingijcsit
 
Adaptive unsharp masking
Adaptive unsharp maskingAdaptive unsharp masking
Adaptive unsharp maskingRavi Teja
 
Image Processing
Image ProcessingImage Processing
Image ProcessingTuyen Pham
 
Review of Digital Image Forgery Detection
Review of Digital Image Forgery DetectionReview of Digital Image Forgery Detection
Review of Digital Image Forgery Detectionrahulmonikasharma
 
Nano Scale Roughness Quantification
Nano Scale Roughness QuantificationNano Scale Roughness Quantification
Nano Scale Roughness QuantificationPratham Ghael
 
Matlab Image Restoration Techniques
Matlab Image Restoration TechniquesMatlab Image Restoration Techniques
Matlab Image Restoration TechniquesDataminingTools Inc
 
Dimensionality reduction
Dimensionality reductionDimensionality reduction
Dimensionality reductionShatakirti Er
 

Was ist angesagt? (20)

JonathanWestlake_ComputerVision_Project2
JonathanWestlake_ComputerVision_Project2JonathanWestlake_ComputerVision_Project2
JonathanWestlake_ComputerVision_Project2
 
Image Recontruction
Image RecontructionImage Recontruction
Image Recontruction
 
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAIN
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAINIMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAIN
IMAGE DENOISING BY MEDIAN FILTER IN WAVELET DOMAIN
 
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...
Filtering Corrupted Image and Edge Detection in Restored Grayscale Image Usin...
 
A proposed accelerated image copy-move forgery detection-vcip2014
A proposed accelerated image copy-move forgery detection-vcip2014A proposed accelerated image copy-move forgery detection-vcip2014
A proposed accelerated image copy-move forgery detection-vcip2014
 
Cg36496501
Cg36496501Cg36496501
Cg36496501
 
FAN search for image copy-move forgery-amalta 2014
 FAN search for image copy-move forgery-amalta 2014 FAN search for image copy-move forgery-amalta 2014
FAN search for image copy-move forgery-amalta 2014
 
Test
TestTest
Test
 
Image Degradation & Resoration
Image Degradation & ResorationImage Degradation & Resoration
Image Degradation & Resoration
 
An efficient approach to wavelet image Denoising
An efficient approach to wavelet image DenoisingAn efficient approach to wavelet image Denoising
An efficient approach to wavelet image Denoising
 
Mnist report ppt
Mnist report pptMnist report ppt
Mnist report ppt
 
Adaptive unsharp masking
Adaptive unsharp maskingAdaptive unsharp masking
Adaptive unsharp masking
 
Image Processing
Image ProcessingImage Processing
Image Processing
 
Review of Digital Image Forgery Detection
Review of Digital Image Forgery DetectionReview of Digital Image Forgery Detection
Review of Digital Image Forgery Detection
 
Nano Scale Roughness Quantification
Nano Scale Roughness QuantificationNano Scale Roughness Quantification
Nano Scale Roughness Quantification
 
Matlab Image Restoration Techniques
Matlab Image Restoration TechniquesMatlab Image Restoration Techniques
Matlab Image Restoration Techniques
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
Dimensionality reduction
Dimensionality reductionDimensionality reduction
Dimensionality reduction
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Digital image processing
Digital image processing  Digital image processing
Digital image processing
 

Andere mochten auch

Blood vessel segmentation of fundus images by major vessel extraction and sub...
Blood vessel segmentation of fundus images by major vessel extraction and sub...Blood vessel segmentation of fundus images by major vessel extraction and sub...
Blood vessel segmentation of fundus images by major vessel extraction and sub...I3E Technologies
 
Vessels Extraction from Retinal Images
Vessels Extraction from Retinal ImagesVessels Extraction from Retinal Images
Vessels Extraction from Retinal ImagesIOSR Journals
 
Comparison of Morphological, Averaging & Median Filter
Comparison of Morphological, Averaging & Median FilterComparison of Morphological, Averaging & Median Filter
Comparison of Morphological, Averaging & Median FilterIJMER
 
Performance analysis of retinal image blood vessel segmentation
Performance analysis of retinal image blood vessel segmentationPerformance analysis of retinal image blood vessel segmentation
Performance analysis of retinal image blood vessel segmentationacijjournal
 
Digital image processing using matlab: filters (detail)
Digital image processing using matlab: filters (detail)Digital image processing using matlab: filters (detail)
Digital image processing using matlab: filters (detail)thanh nguyen
 
Project presentation
Project presentationProject presentation
Project presentationdipti Jain
 
Detection of eye disorders through retinal image analysis
Detection of eye disorders through retinal image analysisDetection of eye disorders through retinal image analysis
Detection of eye disorders through retinal image analysisRahul Dey
 
morphological image processing
morphological image processingmorphological image processing
morphological image processingAnubhav Kumar
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processingVinayak Narayanan
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processingRaghu Kumar
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image ProcessingSahil Biswas
 
Digital image processing img smoothning
Digital image processing img smoothningDigital image processing img smoothning
Digital image processing img smoothningVinay Gupta
 

Andere mochten auch (14)

Median filter Implementation using TMS320C6745
Median filter Implementation using TMS320C6745Median filter Implementation using TMS320C6745
Median filter Implementation using TMS320C6745
 
Blood vessel segmentation of fundus images by major vessel extraction and sub...
Blood vessel segmentation of fundus images by major vessel extraction and sub...Blood vessel segmentation of fundus images by major vessel extraction and sub...
Blood vessel segmentation of fundus images by major vessel extraction and sub...
 
Vessels Extraction from Retinal Images
Vessels Extraction from Retinal ImagesVessels Extraction from Retinal Images
Vessels Extraction from Retinal Images
 
Comparison of Morphological, Averaging & Median Filter
Comparison of Morphological, Averaging & Median FilterComparison of Morphological, Averaging & Median Filter
Comparison of Morphological, Averaging & Median Filter
 
Performance analysis of retinal image blood vessel segmentation
Performance analysis of retinal image blood vessel segmentationPerformance analysis of retinal image blood vessel segmentation
Performance analysis of retinal image blood vessel segmentation
 
Digital image processing using matlab: filters (detail)
Digital image processing using matlab: filters (detail)Digital image processing using matlab: filters (detail)
Digital image processing using matlab: filters (detail)
 
Project presentation
Project presentationProject presentation
Project presentation
 
Detection of eye disorders through retinal image analysis
Detection of eye disorders through retinal image analysisDetection of eye disorders through retinal image analysis
Detection of eye disorders through retinal image analysis
 
morphological image processing
morphological image processingmorphological image processing
morphological image processing
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processing
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processing
 
Image processing ppt
Image processing pptImage processing ppt
Image processing ppt
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Digital image processing img smoothning
Digital image processing img smoothningDigital image processing img smoothning
Digital image processing img smoothning
 

Ähnlich wie E E 458 Project 002

The method of comparing two image files
 The method of comparing two image files The method of comparing two image files
The method of comparing two image filesMinh Anh Nguyen
 
The method of comparing two image files
The method of comparing two image filesThe method of comparing two image files
The method of comparing two image filesMinh Anh Nguyen
 
Image processing
Image processingImage processing
Image processingmaheshpene
 
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docxmercysuttle
 
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdf
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdfAssignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdf
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdfformaxekochi
 
Visual Quality for both Images and Display of Systems by Visual Enhancement u...
Visual Quality for both Images and Display of Systems by Visual Enhancement u...Visual Quality for both Images and Display of Systems by Visual Enhancement u...
Visual Quality for both Images and Display of Systems by Visual Enhancement u...IJMER
 
E E 458 Project 003
E E 458 Project 003E E 458 Project 003
E E 458 Project 003Chad Weiss
 
Research Paper v2.0
Research Paper v2.0Research Paper v2.0
Research Paper v2.0Kapil Tiwari
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET Journal
 
A Biometric Approach to Encrypt a File with the Help of Session Key
A Biometric Approach to Encrypt a File with the Help of Session KeyA Biometric Approach to Encrypt a File with the Help of Session Key
A Biometric Approach to Encrypt a File with the Help of Session KeySougata Das
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingAshok Kumar
 
The Effectiveness and Efficiency of Medical Images after Special Filtration f...
The Effectiveness and Efficiency of Medical Images after Special Filtration f...The Effectiveness and Efficiency of Medical Images after Special Filtration f...
The Effectiveness and Efficiency of Medical Images after Special Filtration f...Editor IJCATR
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab SangeethaSasi1
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfnagwaAboElenein
 
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...CSCJournals
 

Ähnlich wie E E 458 Project 002 (20)

The method of comparing two image files
 The method of comparing two image files The method of comparing two image files
The method of comparing two image files
 
The method of comparing two image files
The method of comparing two image filesThe method of comparing two image files
The method of comparing two image files
 
Image processing
Image processingImage processing
Image processing
 
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
 
Eigenfaces
EigenfacesEigenfaces
Eigenfaces
 
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdf
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdfAssignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdf
Assignment detailsThe image, Baboon aka 4.2.03.tiff, is referenced.pdf
 
Report
ReportReport
Report
 
Visual Quality for both Images and Display of Systems by Visual Enhancement u...
Visual Quality for both Images and Display of Systems by Visual Enhancement u...Visual Quality for both Images and Display of Systems by Visual Enhancement u...
Visual Quality for both Images and Display of Systems by Visual Enhancement u...
 
E E 458 Project 003
E E 458 Project 003E E 458 Project 003
E E 458 Project 003
 
Research Paper v2.0
Research Paper v2.0Research Paper v2.0
Research Paper v2.0
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo Camera
 
A Biometric Approach to Encrypt a File with the Help of Session Key
A Biometric Approach to Encrypt a File with the Help of Session KeyA Biometric Approach to Encrypt a File with the Help of Session Key
A Biometric Approach to Encrypt a File with the Help of Session Key
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
 
The Effectiveness and Efficiency of Medical Images after Special Filtration f...
The Effectiveness and Efficiency of Medical Images after Special Filtration f...The Effectiveness and Efficiency of Medical Images after Special Filtration f...
The Effectiveness and Efficiency of Medical Images after Special Filtration f...
 
Image processing using matlab
Image processing using matlab Image processing using matlab
Image processing using matlab
 
Lec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdfLec_2_Digital Image Fundamentals.pdf
Lec_2_Digital Image Fundamentals.pdf
 
h.pdf
h.pdfh.pdf
h.pdf
 
4 image enhancement in spatial domain
4 image enhancement in spatial domain4 image enhancement in spatial domain
4 image enhancement in spatial domain
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...
A Novel Super Resolution Algorithm Using Interpolation and LWT Based Denoisin...
 

Mehr von Chad Weiss

Advancing Sustainability
Advancing SustainabilityAdvancing Sustainability
Advancing SustainabilityChad Weiss
 
PLC Building Automation and Control Systems
PLC Building Automation and Control SystemsPLC Building Automation and Control Systems
PLC Building Automation and Control SystemsChad Weiss
 
Solar Panel Installations
Solar Panel InstallationsSolar Panel Installations
Solar Panel InstallationsChad Weiss
 
Recommendation Report
Recommendation ReportRecommendation Report
Recommendation ReportChad Weiss
 
Remote Sensing
Remote SensingRemote Sensing
Remote SensingChad Weiss
 
Advancing Sustainability
Advancing SustainabilityAdvancing Sustainability
Advancing SustainabilityChad Weiss
 
Mballa_Weiss_Lab6
Mballa_Weiss_Lab6Mballa_Weiss_Lab6
Mballa_Weiss_Lab6Chad Weiss
 

Mehr von Chad Weiss (14)

Advancing Sustainability
Advancing SustainabilityAdvancing Sustainability
Advancing Sustainability
 
PLC Building Automation and Control Systems
PLC Building Automation and Control SystemsPLC Building Automation and Control Systems
PLC Building Automation and Control Systems
 
Solar Panel Installations
Solar Panel InstallationsSolar Panel Installations
Solar Panel Installations
 
Recommendation Report
Recommendation ReportRecommendation Report
Recommendation Report
 
Remote Sensing
Remote SensingRemote Sensing
Remote Sensing
 
Advancing Sustainability
Advancing SustainabilityAdvancing Sustainability
Advancing Sustainability
 
Final Project
Final ProjectFinal Project
Final Project
 
Mballa_Weiss_Lab6
Mballa_Weiss_Lab6Mballa_Weiss_Lab6
Mballa_Weiss_Lab6
 
Lab 3
Lab 3Lab 3
Lab 3
 
E E 481 Lab 1
E E 481 Lab 1E E 481 Lab 1
E E 481 Lab 1
 
Final Project
Final ProjectFinal Project
Final Project
 
Project004
Project004Project004
Project004
 
Final Paper
Final PaperFinal Paper
Final Paper
 
Final Project
Final ProjectFinal Project
Final Project
 

E E 458 Project 002

  • 1. PENNSYLVANIASTATE UNIVERSITY Digital Image Processing Project 2 Using median filter theory to create a similar function Chad RyanWeiss 3/8/2016
  • 2. Abstract: This report contains information on median filter theory as well as some of the basic MatLab functions and code (written by author) that demonstrates the practicality of such a digital image processing filter.
  • 3. Theory: Median filtering is a common filtering technique used in digital image processing, often used to eliminate unwanted noise in any given image. This type of filter works best for removing salt & pepper noise (which basically consists of black and white specks appearing throughout the image). To operate, the filter must:  Create a square, odd-numbered matrix (mask or window).  Fill the mask with the values from the original noisy image.  Calculate the median value of the mask.  Replace the centermost cell of the mask with the median.  Proceed to the next row or column and repeat. Figure 1: Median Filtering If you refer to Fig. 1 shown above, you will notice that we begin with an image, an intensity matrix consisting of rows and columns each filled with pixel values used to designate the strength or magnitude of the color of the cell (top). Next you will see the mask, which is a square, three-by-three dimensional matrix that has focused itself upon one particular area within the image (center). The mask captures the values of the image and sorts them in ascending order into a data array, which can then be used to determine the median value of the mask (bottom). Once that has been completed, the median value will replace the center value of the mask which will imprint itself upon the original image thus completing the cycle. It will shift and repeat the same process until the entire image has been filtered. This is how the median filter operates.
  • 4. MatLab: The code below shows a MatLab based computer program used to median filter a RGB color image. It takes no more than 180 seconds to filter a 1045-by-585-by-3 dimensional image. % Name: Chad Weiss % Date: March 8, 2016 % Instructor: Dr. Morales % Program: This program is a median filter clear all % Image I = imread('Focus.jpg'); Status = imfinfo('Focus.jpg'); % Noisy Image J = imnoise(I, 'salt & pepper', 0.1); figure; imshow(J); title('Noisy Image'); % Image Conversions Jhsv = rgb2hsv(J); Jhsv0 = [zeros(1,Status.Width,3);Jhsv;zeros(1,Status.Width,3)]; Jhsv0 = [zeros(Status.Height+2,1,3),Jhsv0,zeros(Status.Height+2,1,3)]; Jh = Jhsv0(:,:,1); Js = Jhsv0(:,:,2); Jv = Jhsv0(:,:,3); % Apply Filter for i = 1:Status.Height for j = 1:Status.Width mask = Jh(i:i+2,j:j+2); med = median(sort(transpose(single(mask(1:9))))); Jh(i+1,j+1) = med; end end % Apply Filter for i = 1:Status.Height for j = 1:Status.Width mask = Js(i:i+2,j:j+2); med = median(sort(transpose(single(mask(1:9))))); Js(i+1,j+1) = med; end end % Apply Filter for i = 1:Status.Height for j = 1:Status.Width mask = Jv(i:i+2,j:j+2); med = median(sort(transpose(single(mask(1:9))))); Jv(i+1,j+1) = med; end end F = hsv2rgb(cat(3,Jh,Js,Jv)); figure; imshow(F); title('Filtered Image'); You can see the results on the following page.
  • 5. Figure 2: Noisy Image Figure 3: Filtered Image (using Median Filtering)
  • 6. The code used above was written by the author of this report. There are functions in MatLab that perform similar operations such as the medfilt2 function. See the code below for a demonstration of this function. clear all % Image I = imread('Focus.jpg'); Status = imfinfo('Focus.jpg'); % Noisy Image J = imnoise(I, 'salt & pepper', 0.1); figure; imshow(J); title('Noisy Image'); % Image Conversions Jhsv = rgb2hsv(J); Jhsv0 = [zeros(1,Status.Width,3);Jhsv;zeros(1,Status.Width,3)]; Jhsv0 = [zeros(Status.Height+2,1,3),Jhsv0,zeros(Status.Height+2,1,3)]; Jh = Jhsv0(:,:,1); Js = Jhsv0(:,:,2); Jv = Jhsv0(:,:,3); % Apply Filters Ih = medfilt2(Jh); Is = medfilt2(Js); Iv = medfilt2(Jv); % Image Conversions output = hsv2rgb(cat(3, Ih,Is,Iv)); % Display Image figure; imshow(output); title('Filtered Image'); You can see that the image has been filtered from the original in Fig. 2; however, Fig. 3 appears to have a much better filter than Fig. 4. Figure 4: Filtered Image (using medfilt2)
  • 7. Analysis/Observations: Upon coding the filter, it was noticed that the filtering techniques (both MatLab’s and the author’s) were ineffective against three dimensional images; i.e., images including height, width and depth, suggesting multiple planes. To overcome this challenge it was necessary to convert the RGB (Red, Green, Blue) image into HSV (Hue, Saturation, Value) format; furthermore, it was necessary to create variables holding the individual planes H, S and V, for they are only two dimensional images containing height and width. After isolating the planes, it was possible to apply the filters individually (to H, S and V), eliminating any unwanted noise. Lastly, to recombine the three, two-dimensional filtered images into a three-dimensional filtered image, we simply concatenated the three planes and converted it back to RGB format. Conclusion: In conclusion, the hand-written median filter took about three minutes to run. In comparison, the pre-installed, built-in MatLab functions took only about three seconds to run; however, the quality of the image is much better the first time around for the hand- written version. For an explanation of the code, please refer to Appendix A.
  • 8. Appendix A: Code Variables If you refer to Fig. 5, you will see the list of variables used in running the median filter computer program. I: This variable contains the original image. J: This variable contains the noisy image. Figure 5: List of Variables
  • 9. Jhsv: This variable contains the hsv noisy image. Jhsv0: This variable contains the hsv noisy image w/ a zero border (1 pixel black border). Jh: This variable contains the h-plane image of the Jhsv0 image.
  • 10. Js: This variable contains the s-plane image of the Jhsv0 image. Jv: This variable contains the v-plane image of the Jhsv0 image.
  • 11. Status: This variable contains the original image I information. mask: This variable is the 3x3x3 dimensional mask used in filtering the noisy images. med: This variable contains the median value of the mask. i: This is a row counter variable. j: This is a column counter variable. F: This variable contains the filtered image.
  • 12. Functions: imread(_): Reads-in an image imfinfo(_): Reads-in image information imshow(_): Displays an image imnoise(_): Adds noise to an image rgb2hsv(_): Converts a RGB image to HSV format hsv2rgb(_): Converts a HSV image to RGB format single(_): Converts data to the datatype single transpose(_): Transposes matrices sort(_): Sorts any matrix or array in ascending order median(_): Determines the median value of any matrix or array cat(_): Concatenates arrays help: See above