Insight Through Computing 23. Working with Image Files Cont’d Filtering Noise Edge Detection.

Slides:



Advertisements
Similar presentations
CS Spring 2009 CS 414 – Multimedia Systems Design Lecture 4 – Digital Image Representation Klara Nahrstedt Spring 2009.
Advertisements

Image Processing. Image processing Once we have an image in a digital form we can process it in the computer. We apply a “filter” and recalculate the.
Computational Biology, Part 23 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
Spatial Filtering (Chapter 3)
October 2, 2014Computer Vision Lecture 8: Edge Detection I 1 Edge Detection.
1 Video Processing Lecture on the image part (8+9) Automatic Perception Volker Krüger Aalborg Media Lab Aalborg University Copenhagen
1Ellen L. Walker ImageJ Java image processing tool from NIH Reads / writes a large variety of images Many image processing operations.
DIGITAL IMAGE PROCESSING CMSC 150: Lecture 14. Conventional Cameras  Entirely chemical and mechanical processes  Film: records a chemical record of.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
6/9/2015Digital Image Processing1. 2 Example Histogram.
Insight Through Computing 22. Working with Image Files imread, imwrite, imshow, uint8, rgb2gray.
MSU CSE 803 Stockman Linear Operations Using Masks Masks are patterns used to define the weights used in averaging the neighbors of a pixel to compute.
Image representation using arrays Image processing examples
1 Image Filtering Readings: Ch 5: 5.4, 5.5, 5.6,5.7.3, 5.8 (This lecture does not follow the book.) Images by Pawan SinhaPawan Sinha formal terminology.
Insight Through Computing 18. Two-Dimensional Arrays Set-Up Rows and Columns Subscripting Operations Examples.
1 Image filtering Images by Pawan SinhaPawan Sinha.
1 Image filtering
Lec 5 Feb 10 Goals: analysis of algorithms (continued) O notation summation formulas maximum subsequence sum problem (Chapter 2) three algorithms image.
Image Analysis Preprocessing Arithmetic and Logic Operations Spatial Filters Image Quantization.
Computer Vision Lecture 3: Digital Images
MSU CSE 803 Linear Operations Using Masks Masks are patterns used to define the weights used in averaging the neighbors of a pixel to compute some result.
Most slides from Steve Seitz
Presentation Image Filters
Chapter 3: Image Restoration Geometric Transforms.
Spatial Filtering: Basics
Digital Image Processing Image Enhancement Part IV.
Digital Image Processing
Digital Image Processing CCS331 Relationships of Pixel 1.
Filtering and Enhancing Images. Major operations 1. Matching an image neighborhood with a pattern or mask 2. Convolution (FIR filtering)
Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T Computer Vision Tahun: 2010.
infinity-project.org Engineering education for today’s classroom 2 Outline How Can We Use Digital Images? A Digital Image is a Matrix Manipulating Images.
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
Image processing Fourth lecture Image Restoration Image Restoration: Image restoration methods are used to improve the appearance of an image.
1 Regions and Binary Images Hao Jiang Computer Science Department Sept. 25, 2014.
Chapter 5: Neighborhood Processing
Image Processing Part II. 2 Classes of Digital Filters global filters transform each pixel uniformly according to the function regardless of its location.
Computer Vision Introduction to Digital Images.
1 Regions and Binary Images Hao Jiang Computer Science Department Sept. 24, 2009.
Lecture # 19 Image Processing II. 2 Classes of Digital Filters Global filters transform each pixel uniformly according to the function regardless of.
L23. Working with Image Files imread, imwrite, imshow, uint8, rgb2gray.
October 1, 2013Computer Vision Lecture 9: From Edges to Contours 1 Canny Edge Detector However, usually there will still be noise in the array E[i, j],
By Dr. Rajeev Srivastava
CS Spring 2010 CS 414 – Multimedia Systems Design Lecture 4 – Audio and Digital Image Representation Klara Nahrstedt Spring 2010.
SUREILLANCE IN THE DEPARTMENT THROUGH IMAGE PROCESSING F.Y.P. PRESENTATION BY AHMAD IJAZ & UFUK INCE SUPERVISOR: ASSOC. PROF. ERHAN INCE.
Instructor: Mircea Nicolescu Lecture 5 CS 485 / 685 Computer Vision.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 3. Time Complexity Calculations.
Non-linear filtering Example: Median filter Replaces pixel value by median value over neighborhood Generates no new gray levels.
Lecture 10 Chapter 5: Image Restoration. Image restoration Image restoration is the process of recovering the original scene from the observed scene which.
L24. More on Image File Processing
Image Pre-Processing in the Spatial and Frequent Domain
Fourier Transform: Real-World Images
Singular Value Decomposition
Computer Vision Lecture 9: Edge Detection II
Image filtering Images by Pawan Sinha.
Image filtering Images by Pawan Sinha.
Image filtering Images by Pawan Sinha.
Spatial operations and transformations
Technique 6: General gray-level transformations
Digital Image Processing Week IV
Most slides from Steve Seitz
Image filtering Images by Pawan Sinha.
Linear Operations Using Masks
Technique 6: General gray-level transformations
Programming for Engineers in Python
L19. Two-Dimensional Arrays
Image Filtering Readings: Ch 5: 5. 4, 5. 5, 5. 6, , 5
Most slides from Steve Seitz
Intro Math Problem Solving October 31
Intro Math Problem Solving November 2
Spatial operations and transformations
Presentation transcript:

Insight Through Computing 23. Working with Image Files Cont’d Filtering Noise Edge Detection

Insight Through Computing Pictures as Arrays A black and white picture can be encoded as a 2D Array Typical: 0 <= A(i,j) <= 255 (black) (white) Values in between correspond to different levels of grayness.

1458-by Just a Bunch of Numbers

1458-by Dirt! Note how the “dirty pixels” look out of place

Insight Through Computing Can We Filter Out the “Noise”?

Insight Through Computing 1458-by ? ? ? ? Idea Assign “typical” neighborhood gray values to “dirty pixels”

Insight Through Computing Getting Precise “Typical neighborhood gray values” Could use Median Or Mean radius 1 radius 3 We’ll look at “Median Filtering” first…

Insight Through Computing Median Filtering Visit each pixel. Replace its gray value by the median of the gray values in the “neighborhood”.

Insight Through Computing Using a radius 1 “Neighborhood” BeforeAfter

Insight Through Computing How to Visit Every Pixel m = 9 n = 18 for i=1:m for j=1:n Compute new gray value for pixel (i,j). end

Insight Through Computing i = 1 j = 1 Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = 1 j = 2 Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = 1 j = 3 Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = 1 j = n Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = 2 j = 1 Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = 2 j = 2 Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing i = m j = n Original: Filtered: Replace with the median of the values under the window.

Insight Through Computing What We Need… (1) A function that computes the median value in a 2-dimensional array C: m = medVal(C) (2) A function that builds the filtered image by using median values of radius r neighborhoods: B = medFilter(A,r)

Insight Through Computing Computing Medians x : x = sort(x) x : n = length(x); % n = 7 m = ceil(n/2); % m = 4 med = x(m); % med = 36 If n is even, then use : med = ( x(m) + x(m+1) )/2

Insight Through Computing Median of a 2D Array function med = medVal(C) [p,q] = size(C); x = []; for k=1:p x = [x C(k,:)]; end Compute median of x and assign to med.

Insight Through Computing Medians vs Means A = Median = 154 Mean = 154.2

Insight Through Computing Medians vs Means A = Median = 154 Mean = 148.2

Insight Through Computing Back to Filtering… m = 9 n = 18 for i=1:m for j=1:n Compute new gray value for pixel (i,j). end

Insight Through Computing Window Inside… m = 9 n = 18 New gray value for pixel (7,4) = medVal( A(6:8,3:5) )

Insight Through Computing Window Partly Outside… m = 9 n = 18 New gray value for pixel (7,1) = medVal( A(6:8,1:2) )

Insight Through Computing Window Partly Outside… m = 9 n = 18 New gray value for pixel (9,18) = medVal( A(8:9,17:18) )

Insight Through Computing function B = medFilter(A,r) % B from A via median filtering % with radius r neighborhoods. [m,n] = size(A); B = uint8(zeros(m,n)); for i=1:m for j=1:n C = pixel (i,j) neighborhood B(i,j) = medVal(C); end

Insight Through Computing The Pixel (i,j) Neighborhood iMin = max(1,i-r) iMax = min(m,i+r) jMin = max(1,j-r) jMax = min(n,j+r) C = A(iMin:iMax,jMin:jMax) r = 1r = 2 A m n

Insight Through Computing B = medFilter(A)

Insight Through Computing Original

Insight Through Computing What About Using the Mean instead of the Median? Replace each gray value with the average gray value in the radius r neighborhood.

Insight Through Computing Mean Filter with r = 3

Insight Through Computing Mean Filter with r = 10

Insight Through Computing Why it Fails The mean does not capture representative values.

Insight Through Computing And Median Filters Leave Edges (Pretty Much) Alone Inside the box, the 200’s stay at 200 and the 100’s stay at 100.

Insight Through Computing Finding Edges

Insight Through Computing What is an Edge? Near an edge, grayness values change abruptly

Insight Through Computing General plan for showing the edges in in image Identify the “edge pixels” Highlight the edge pixels –make edge pixels white; make everything else black

Insight Through Computing General plan for showing the edges in in image Identify the “edge pixels” Highlight the edge pixels –make edge pixels white; make everything else black W H I T E BLACK

Insight Through Computing The Rate-of-Change-Array Suppose A is an image array with integer values between 0 and 255 B(i,j) be the maximum difference between A(i,j) and any of its eight neighbors.

Insight Through Computing The Rate-of-Change-Array Suppose A is an image array with integer values between 0 and 255 Let B(i,j) be the maximum value in A(max(1,i-1):min(m,i+1),... max(1,j-1):min(n,j+1)) - A(i,j) Neighborhood of A(i,j)

Insight Through Computing Rate-of-change example Rate-of-change at middle pixel is 30 Be careful! In “uint8 arithmetic” 57 – 60 is 0

Insight Through Computing function Edges(jpgIn,jpgOut,tau) % jpgOut is the “edge diagram” of image jpgIn. % At each pixel, if rate-of-change > tau % then the pixel is considered to be on an edge. A = rgb2gray(imread(jpgIn)); [m,n] = size(A); B = uint8(zeros(m,n)); for i = 1:m for j = 1:n B(i,j) = ????? end Built-in function to convert to grayscale. Returns 2-d array.

Insight Through Computing Recipe for rate-of-change B(i,j) % The 3-by-3 subarray that includes % A(i,j) and its 8 neighbors Neighbors = A(i-1:i+1,j-1:j+1); % Subtract A(i,j) from each entry Diff= abs(double(Neighbors)–... double(A(i,j))); % Compute largest value in each column colMax = max(Diff); % Compute the max of the column max’s B(i,j) = max(colMax);

Insight Through Computing function Edges(jpgIn,jpgOut,tau) % jpgOut is the “edge diagram” of image jpgIn. % At each pixel, if rate-of-change > tau % then the pixel is considered to be on an edge. A = rgb2gray(imread(jpgIn)); [m,n] = size(A); B = uint8(zeros(m,n)); for i = 1:m for j = 1:n B(i,j) = ????? end

Insight Through Computing function Edges(jpgIn,jpgOut,tau) % jpgOut is the “edge diagram” of image jpgIn. % At each pixel, if rate-of-change > tau % then the pixel is considered to be on an edge. A = rgb2gray(imread(jpgIn)); [m,n] = size(A); B = uint8(zeros(m,n)); for i = 1:m for j = 1:n Neighbors = A(max(1,i-1):min(i+1,m),... max(1,j-1):min(j+1,n)); B(i,j)=max(max(abs(double(Neighbors)–... double(A(i,j))))); end

Insight Through Computing “Edge pixels” are now identified; display them with maximum brightness (255) A B(i,j) if B(i,j) > tau B(i,j) = 255; end threshold

Insight Through Computing function Edges(jpgIn,jpgOut,tau) % jpgOut is the “edge diagram” of image jpgIn. % At each pixel, if rate-of-change > tau % then the pixel is considered to be on an edge. A = rgb2gray(imread(jpgIn)); [m,n] = size(A); B = uint8(zeros(m,n)); for i = 1:m for j = 1:n Neighbors = A(max(1,i-1):min(i+1,m),... max(1,j-1):min(j+1,n)); B(i,j)=max(max(abs(double(Neighbors)–... double(A(i,j))))); if B(i,j) > tau B(i,j) = 255; end

Insight Through Computing function Edges(jpgIn,jpgOut,tau) % jpgOut is the “edge diagram” of image jpgIn. % At each pixel, if rate-of-change > tau % then the pixel is considered to be on an edge. A = rgb2gray(imread(jpgIn)); [m,n] = size(A); B = uint8(zeros(m,n)); for i = 1:m for j = 1:n Neighbors = A(max(1,i-1):min(i+1,m),... max(1,j-1):min(j+1,n)); B(i,j)=max(max(abs(double(Neighbors)–... double(A(i,j))))); if B(i,j) > tau B(i,j) = 255; end imwrite(B,jpgOut,’jpg’)

Insight Through Computing Threshhold = 40

Insight Through Computing Threshhold = 20

Insight Through Computing Threshhold = 30