440 likes | 614 Views
Roger S. Gaborski. Foundations of Computer Vision Lecture 12. QUIZ 1. Chest Radiographic Image. separate lung region and bone region. What information can we extract from the image – separate lung region and bone region? As a first step, techniques we can try: Thresholding Imadjust
E N D
Roger S. Gaborski Foundations of Computer VisionLecture 12 Roger S. Gaborski
QUIZ 1 Roger S. Gaborski
Chest Radiographic Image separate lung region and bone region Roger S. Gaborski
What information can we extract from the image – separate lung region and bone region? • As a first step, techniques we can try: • Thresholding • Imadjust • Edge detection • Texture Roger S. Gaborski
Histogram of Image Roger S. Gaborski
Threshold = .4 Roger S. Gaborski
Threshold = .6 Roger S. Gaborski
Otsu’s graythreshThresholdingMethod • Algorithm assumes the image’s histogram is bi-model • Finds the optimal threshold to separate the two classes of pixels Roger S. Gaborski
Matlab - Otsu’s Method • level = graythresh(Ig) • figure, imshow(Ig>level), title('Graythresh Level') • level = 0.5373 Roger S. Gaborski
Threshold Level Determined by Otsu Method Roger S. Gaborski
Otsu’s method, continued • Since the histogram is not bi-modal should not expect good separation between lungs and bones Roger S. Gaborski
imadjust Roger S. Gaborski
Original and imadjust Image Roger S. Gaborski
Edge Detection fh = fspecial('sobel'); %horiz edge fv = fh'; %vertical edge i_horiz = imfilter(Ig, fh); figure, imshow(i_horiz, []), title('Horizontal Edges') i_vert = imfilter(Ig, fv); figure, imshow(i_vert, []),title('Vertical Edges') Roger S. Gaborski
Horizontal Edges Roger S. Gaborski
How do I find pixel locations of edges with largest magnitude? Roger S. Gaborski
Vertical Edges Roger S. Gaborski
Canny- stddev = 2 Roger S. Gaborski
Canny- stddev = 3 Roger S. Gaborski
Laplacian of Gaussian, stddev =2 Roger S. Gaborski
Laplacian of Gaussian, stddev=3 Roger S. Gaborski
Laplacian of Gaussian, stddev =2.5 Roger S. Gaborski
Sensitivity of standard deviation: • Compare the last three images • Significant difference with a small change in standard deviation • How do you automatically choose the standard deviation if you have a large collection of images that you need to process? Roger S. Gaborski
Reconsider Thresholding • Does it make sense to have only one threshold value? • Physically, maybe the image cannot be separated into only 2 classes • Consider more than one thresholding values Roger S. Gaborski
IMQUANTIZE • imquantize Quantize image using specified quantization levels and output values. • QUANT_A = imquantize(A, LEVELS) uses the quantization levels specified • in the 1xN vector LEVELS to convert image A into an output image • QUANT_A with N+1 discrete levels. The entries in LEVELS have to be in • strictly increasing order. The output image QUANT_A contains integer • values in the range [1 (N+1)] assigned as per the criterion below: • If A(k) <= LEVELS(1), then QUANT_A(k) = 1 • If LEVELS(m-1) < A(k) <= LEVELS(m), then QUANT_A(k) = m • If A(k) >LEVELS(N), then QUANT_A(k) = N+1 Roger S. Gaborski
imquantize > A =[1:10] A = 1 2 3 4 5 6 7 8 9 10 LEVELS = [5] % N=1 %Results in 2 levels, N+1 = 2 % Values less than and equal to 5 are assigned a value 1 %Values greater than 5 are assigned value 2 L = imquantize(A,LEVELS) L = 1 1 1 1 1 2 2 2 2 2 A = 1 2 3 4 5 6 7 8 31 310 >> L = imquantize(A,LEVELS) L = 1 1 1 1 1 2 2 2 2 2 Roger S. Gaborski
Multi-levels LEVELS = [3,7] %Two levels, N=2, N+1 = 3 L = imquantize(A,LEVELS) L = 1 1 1 2 2 2 2 3 3 3 1 to 3 is first level, 4-7 is second level and 8 to 10 is 3rd level Roger S. Gaborski
>> R = rand(5) R = 0.7577 0.7060 0.8235 0.4387 0.4898 0.7431 0.0318 0.6948 0.3816 0.4456 0.3922 0.2769 0.3171 0.7655 0.6463 0.6555 0.0462 0.9502 0.7952 0.7094 0.1712 0.0971 0.0344 0.1869 0.7547 >> LEVELS = [.3] LEVELS = 0.3000 >> L = imquantize(R,LEVELS) L = 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 1 2 Roger S. Gaborski
Could we apply this technique to segmentation (lungs and bones)? >> R = rand(100); >> LEVELS = [.1 .2 .5 .6 .7]; >> L = imquantize(R,LEVELS); >> R(1,1:10) = 0.270 0.417 0.963 0.301 0.916 0.736 0.146 0.456 0.109 0.163 >> L(1,1:10) = 3 3 6 3 6 6 2 3 2 2 BUT, HOW DO WE SELECT LEVELS? Roger S. Gaborski
Displaying the L image: label2rgb • label2rgb Convert label matrix to RGB image. • The RGB matrix can then be visualized LEVELS = [3,7] L = imquantize(A,LEVELS) L = 1 1 1 2 2 2 2 3 3 3 1 to 3 is first level, 4-7 is second level and 8 to 10 is 3rd level iData=label2rgb(L) iData(:,:,1) = 0 0 0 0 0 0 0 255 255 255 iData (:,:,2) = 0 0 0 255 255 255 255 255 255 255 iData(:,:,3) = 255 255 255 255 255 255 255 0 0 0 figure, imshow(iData,'InitialMagnification','fit') Roger S. Gaborski
iData Roger S. Gaborski
THRESH = multithresh(A, N) • THRESH = multithresh(A, N) computes N thresholds for image A using the Otsu's method and returns them in THRESH. • THRESH is a 1xN vector which can be used to convert A into an image with (N+1) discrete levels using IMQUANTIZE. Roger S. Gaborski
>> I = imread('chestRadiograph1.png'); • I = rgb2gray(I); • Id = im2double(I); • thresh = multithresh(I,3) = 0.4416 0.5356 0.6233 seg_I= imquantize(Id,thresh); • RGB = label2rgb(seg_I); • figure, imshow(RGB) Roger S. Gaborski
Histogram of Image Interval 1 2 3 Interval 4 Roger S. Gaborski
thresh = multithresh(I,3) = 0.4416 0.5356 0.6233 I(20,20:30) = Columns 1 through 7 0.4235 0.4235 0.4235 0.4275 0.4275 0.4353 0.4431 Columns 8 through 11 0.4549 0.4667 0.4784 0.4824 >> seg_I(20,20:30) 1 1 1 1 1 1 2 2 2 2 2 Roger S. Gaborski
Multi-level Thresholding Roger S. Gaborski
Another Example Roger S. Gaborski
>> i = imread('Powder21.jpg'); >> i = im2double(i); >> Ig = rgb2gray(i); >> figure, imshow(Ig) >> thresh = graythresh(Ig) thresh = 0.3765 >> Igt = Ig>thresh; >> figure, imshow(Igt) Roger S. Gaborski
I=imread('Powder21.jpg'); >> I = rgb2gray(I); >> I=im2double(I); >> thresh=multithresh(I,4); >> seg_I = imquantize(I,thresh); Roger S. Gaborski
RGB = label2rgb(seg_I); figure, imshow(RGB) Roger S. Gaborski