ECE 480 Lab 9

Ryan Eslinger and Mike Fuson

16 February 2011

 

Circles                           Erroded Circles               Histogram of Circles

 

To count the Circles we used the ultimate point command in ImageJ which returns a pixel in the position of the original shape and gives the pixel a grey value equal to the radius of the shape. We then looked at the histogram of this output which told us that there were 3 circles with radius of 16, 7 with radius 17, 10 with radius 20 and 4 with radius 54.

Paragraph                   letter b                hit-or-miss output

To count the occurrences of the letter b we used the following MATLAB code.  At the end of the code it would output the variable count which equaled the number of occurrences.  In this case it was 5.

 

% Michael Fuson

% Ryan Eslinger

% ECE480

% Lab9

 

clear;

clc;

 

 img = im2single(rgb2gray(imread('black cat words.bmp')));

%  hhist2d = video.Histogram;

%  prob_dist = step(hhist2d,img).';

 

 for i=1:283

     for j=1:729

         if img(i,j)>.5

             img(i,j)=1;

         else

             img(i,j)=0;

         end

     end

end

 

 y=1;

 for i=17:77

     x=1;

     for j=143:185

         b(y,x)=img(i,j);

         x=x+1;

     end

     y=y+1;

end

 

 figure

imshow(img)

figure

imshow(b)

 

 output=bwhitmiss(img,b);

output=+output;

figure

imshow(output)

 

count = 0;

 

for j = 2:282

    for i = 2:728

        if output(j,i) == 1 && output(j+1,i+1) == 0 && output(j-1,i-1)== 0 && output(j-1,i+1) == 0 && output(j+1,i-1) == 0 && output(j+1,i) == 0 && output(j-1,i) == 0 && output(j,i+1) == 0 && output(j,i-1) == 0

            count = count + 1;

        else

        end

    end

end

 

 count

 

We feel like we succeeded in this lab as we correctly counted the number of circles and letter b’s.

 

ECE 480 Lab 8

Ryan Eslinger and Mike Fuson

15 February 2011

 

We were not able to make the Huffman code work in Matlab but what we tried to do is the following. First we took the histories of the image then arranged the values according to their probability.  We then added the least probable values and resorted the array. It was difficult to figure out how to track the resorting and making a tree that could then be used to produce the actual code. We would do this till the there were only two values left and then go down the tree to produce the code.

Lossless:

Start       Lossless Code       Lossless deCode

 

The decoded image was the exact same as the original.  All detail was retained.

 

%Michael Fuson

%Ryan Eslinger

%ECE 480

%Lab8 Lossless

 

lena = im2single(rgb2gray(imread('lena.jpg')));

imshow(lena);

figure(1),title('Lena');

 

lenacode = lena;

 

for j = 1:512

    pred = lena(j,1);

    for i = 1:512

        lenacode(j,i) = lenacode(j,i) - pred;

        lenacode(j,1) = lena(j,1);

        pred = lenacode(j,i);

    end

end

 

figure(2)

imshow(lenacode);

title('LosslessLena');

 

lenadecode = lenacode;

for j = 1:512

    predde = lenacode(j,1);

    for i = 1:512

        lenadecode(j,i) = lenacode(j,i) + predde;

        predde = lenacode(j,i);

    end

    lenadecode(j,1) = lenacode(j,1);

end

 

figure(3)

imshow(lenadecode);

title('Lena Decode');

 

Lossy:

Start       Lossy Code Delta = 0.1       Lossy deCode Delta = 0.1

 

               Lossy Code Delta = 0.3       Lossy deCode Delta = 0.3

 

In both cases the decoded image was not the same as the original.  Details were lost.  The Step size of 0.1 was closer to the original when decoded.

 

%Michael Fuson

%Ryan Eslinger

%ECE 480

%Lab8 Lossy

 

lena = im2single(rgb2gray(imread('lena.jpg')));

imshow(lena);

figure(1),title('Lena');

 

lenacode = lena;

delt = .1;

 

for j = 1:512

    pred = lena(j,1);

    for i = 1:512

        diff = lenacode(j,i) - pred;

        lenacode(j,1) = lena(j,1);

        if diff >= 0

            pred = pred + delt;

            lenacode(j,i) = delt;

        else

            pred = pred - delt;

            lenacode(j,i) = -delt;

        end

    end

end

 

figure(2)

imshow(lenacode);

title('LosslessLena');

 

lenadecode = lenacode;

for j = 1:512

    predde = lenacode(j,1);

    for i = 1:512

        lenadecode(j,i) = lenacode(j,i) + predde;

        predde = lenadecode(j,i);

    end

    lenadecode(j,1) = lenacode(j,1);

end

 

figure(3)

imshow(lenadecode);

title('Lena Decode');

 

We feel that we successfully completed this lab.

 

ECE 480 Lab 7

Ryan Eslinger and Mike Fuson

26 January 2011

Compression:

For the Boats compression we used a threshold of 100 and for the Bridge we used the default threshold of 10. For the Boats image the file size went from 55KB to 46KB and for the Bridge image the file size went from 61 KB to 58KB. This shows that changing the threshold changes how much the image is compressed using the FSW module.

Boats Original              Boats Compressed

Bridge Original            Bridge Compressed

Filter:

For the filtering we used the FSW transform plugin. We did three iterations of the wavelet algorithm on each image and then removed the top left portion of the picture that represented an average of the picture. We then ran the process in reverse and obtained the images shown. The resulting images contain the edges of the picture which means that the process acted like a highpass filter. There was also a lot of ringing in the images which is indicative of a very sharp filter.

We also used different wavelets and repeated the process. For the different wavelets the intermediate pictures looked very different but the end results were very similar.

Boats Original              Proc-Boats        WT-Boats      Boats 3iterations

Boats 3iterations filtered       boats 3iterations reconstructed             Boats with edges reconstructed

 

Bridge Original           Proc-Bridge              WT-Bridge

 

Bridge 3iteration        Bridge 3iteration filtered

 

Bridge Orth                 Bridge B4                 Bridge Dual

 

We feel that we successfully completed this lab.

 

ECE 480 Lab 6

Ryan Eslinger and Mike Fuson

19 January 2011

 

Benham’s Disc:

Below is a picture of our Benham Disk stationary and rotation. No color is visible on the picture in motion because the color effect is produced by the actual spinning of the disk. It is not complete understood why this pattern produces colors while moving. One theory is that the three different cones in the eye have different delays in their perception so somehow when the motion is at the right frequency color is perceived to appear

Stationary     Spinning

 

Color Brightening:

 

RGB:

Original      Stack      Red          Green             Blue

Histogram Blue            Equalized Histogram Blue

Equalized Blue          Restack           New Image

 

HSB:

Original      Stack      Hue          Saturation             Brightness

Histogram Brightness            Equalized Histogram Brightness

Equalized Brightness          Restack           New Image

 

As learned in class, modifying just one color affects the other colors when it is restacked.  The colors were changed.  By modifying the brightness in the HSB components, none of the colors were changed and the image simply became brighter.

Pseudo Color Using Look Up Tables:

 

Original Tooth        LUT      New Tooth                       

We feel that we successfully completed this lab.


ECE 480 Lab 5

Ryan Eslinger and Mike Fuson

12 January 2011

 

Slow Blur Method and Results:

Stationary Image    Blurred Image    Deblurred Image

% Michael Fuson

% Ryan Eslinger

% ECE480

% Lab5

% Slow clock deblurr

 

clc;

clear;

 

slowblurr = im2double(imread('clock moving slowly.bmp'));

imshow(slowblurr);

figure(1),title('clock moving slowly');

 

 

noise_var=2.5000e-005;

Len=55;

Theta=3;

 

    PSF=fspecial('motion',Len,Theta);

    estimated_nsr = noise_var / var(slowblurr(:));

 

    Rslowblur = deconvwnr(slowblurr, PSF, estimated_nsr);

    figure(2), imshow(Rslowblur)

    title('Restoration of Blurred Image')

   

Rapid Blur Method and Results:

Stationary Image    Blurred Image    Deblurred Image

% Michael Fuson

% Ryan Eslinger

% ECE480

% Lab5

% Rapid clock deblurr

clc;

clear;

 

rapidblurr = im2double(imread('clock moving rapidly.bmp'));

imshow(rapidblurr);

figure(1),title('clock moving rapidly');

 

Theta=6;

noise_var=5.6e-5;

Len=115;

 

PSF=fspecial('motion',Len,Theta);

estimated_nsr = noise_var / var(rapidblurr(:));

 

Rrapidblur = deconvwnr(rapidblurr, PSF, estimated_nsr);

figure(115), imshow(Rrapidblur)

title('Restoration of Blurred Image')

 

We used Matlab to correct the degradation caused by the motion blur. Specifically we used the deconvwnr function which deconvolves an image using the wiener filter algorithm that we have learned about in class. To make the actual filter used to convolve with the image we used the fspecial command which has a specific parameter that allows it to approximate the degradation that occurs from camera motion. This is not totally ideal since the clock was moving and not the camera itself but it work sufficiently well. In the filter parameter we specify the amount the image was moving horizontally with the Len variable and the amount of rotational motion is specified by the theta variable.

We determined the Len and theta variables experimentally but running the code and comparing its output to the ideal image provided. For the slow moving clock we decided on a Len value of 55 and for the fast moving clock we decided on a Len value of 115. The theta values were small because the clock mostly had horizontal motion. Bellow you can see the resulting images and the specific code that we used to obtain them.

               As mentioned in class it was very difficult to do this lab with great success.  While we managed to deblur the slow moving clock fairly successfully, we found the rapid moving clock to be much more difficult.  We do however feel that we did make an improvement to the rapid clock particularly around the T and the lower dial.

ECE 480 Lab 4

Ryan Eslinger and Mike Fuson

5 January 2011

Original Bridge

Large Pinhole    Large Pinhole Convolution    Large Pinhole Correlation

Small Pinhole    Small Pinhole Convolution    Small Pinhole Correlation

Two Pinholes    Two Pinholes Convolution    Two Pinholes Correlation

Dots Original    Dots Correlation

Commentary On Part 2:

When we convolved the images with themselves we saw the pinholes that were originally used to make the images.

Commentary On Part 3:

The diameter of the circles was 43 pixels while the distance between the minima and the central maximum was 44 pixels.

We have completed the lab and believe we were successful in doing so.

 

 

ECE 480 Lab 3

Ryan Eslinger and Mike Fuson

15 December 2010

Original Image     Original FFT     

Filter to Remove Sinusoid     Image After Sinusoid     FFT After Sinusoid

Image After Median Filter     FFT After Median     Histogram After Median

Image After Enhance     FFT After Enhance     Histogram After Enhance

Image After Simple Median Only

First we took an FFT of the original image.  We located the sinusoid and made a filter with two black circles at the location of the sinusoid.  We blurred these black dots with a Gaussian filter to reduce ringing.  We then did a custom FFT filter with our filter to remove the sinusoid.  Next we did a median filter to remove the shot noise.  Finally we enhanced the image using the equalize function.

We feel that the lab was successful as we removed the noise from the image.

 

ECE 480 Lab 2

Ryan Eslinger and Mike Fuson

 8 December 2010

 

 

Histogram:

Histogram Before             Histogram After

First we equalized the image.

Image Before                    Image After

We used a median filter to remove the shot noise.

The equalization spread the histogram and added contrast to the picture so that the image was easily visible. Once that was done there was lots of salt and pepper noise which we cleaned up using the median filter.  This did cause some blurring.

Masks:

Original Image

Simple Average Mask                     Simple Average Image

1

1

1

1

1

1

1

1

1

Weighted Average Mask Weighted Average Image

1

2

1

2

4

2

1

2

1

Horizontal Sobel Mask                   Horizontal Sobel Image

-1

0

1

-2

0

2

-1

0

1

Vertical Sobel Mask                        Vertical Sobel Image

-1

-2

-1

0

0

0

1

2

1

Laplacian Mask                                Laplacian Image

1

1

1

1

-8

1

1

1

1

In order to add these masks we used ImageJ’s convolve option which is located under Process\Filters.  We then simply typed in the filters that we wished to use.  The simple average mask blurred the image.  The weighted average mask blurred the

 image and brightened the image.The Sobel masks detected edges in one direction.  The Laplacian Mask detected all edges.

Fourier Image:

A)     Here is the code we used:

// This macro creates a sine image

width = 512; height = 512;

xc = width/2; yc = height/2;

newImage("Sine wave", "32-bit black", width, height, 1);

for (y= 0; y<height; y++) {

for (x= 0; x<width; x++) {

setPixel(x, y, f1(x,y));

}

if (y%20==0) showProgress(y, height);

}

//resetMinAndMax();

// makeLine(0, 0, width, height);

// run("Plot Profile");

exit;

function f0(x) {return 2*x*x-3;}

function f1(x,y) {return sin(1/3x);}

function f2(x,y) {return sin(x/2+y/3)+sin(y/3);}

function f3(x) {return sqrt(x);}

function f4(x) {if (x==0) return 0; else return log(x);}

function f5(x) {return exp(x/100);}

Sinusoidal Image              Power Spectra                   Phase Spectra                    FFT         Plot of Imaginary

B)     Here is the code we used:

// This macro creates a sine image

width = 512; height = 512;

xc = width/2; yc = height/2;

newImage("Sine wave", "32-bit black", width, height, 1);

for (y= 0; y<height; y++) {

for (x= 0; x<width; x++) {

setPixel(x, y, f1(x,y));

}

if (y%20==0) showProgress(y, height);

}

//resetMinAndMax();

// makeLine(0, 0, width, height);

// run("Plot Profile");

exit;

function f0(x) {return 2*x*x-3;}

function f1(x,y) {return sin(1/3x);}                                      *Note the 1/3 is where we changed the frequency

function f2(x,y) {return sin(x/2+y/3)+sin(y/3);}                 first we changed it to 1/10 and then 2

function f3(x) {return sqrt(x);}

function f4(x) {if (x==0) return 0; else return log(x);}

function f5(x) {return exp(x/100);}

This plot is a a sinusoid at frequency 1/10. Notice how close the dots are on the Power Spectrum plot.

Sinusoidal Image w/Frequency 1/10                         Power Spectra

This plot is a a sinusoid at frequency 2. Notice how far apart the dots are on the Power Spectrum plot.

Sinusoidal Image w/ Frequency 2                              Power Spectra

C)     Here is the code we used:

// This macro creates a sine image

width = 512; height = 512;

xc = width/2; yc = height/2;

newImage("Sine wave", "32-bit black", width, height, 1);

for (y= 0; y<height; y++) {

for (x= 0; x<width; x++) {

setPixel(x, y, f1(x,y));

}

if (y%20==0) showProgress(y, height);

}

//resetMinAndMax();

// makeLine(0, 0, width, height);

// run("Plot Profile");

exit;

function f0(x) {return 2*x*x-3;}

function f1(x,y) {return sin(1/3x+0.2);}

function f2(x,y) {return sin(x/2+y/3)+sin(y/3);}

function f3(x) {return sqrt(x);}

function f4(x) {if (x==0) return 0; else return log(x);}

function f5(x) {return exp(x/100);}

You can see the phase shift most easily on the plot of the imaginary image. Notice that the whole plot is shifted.

Sinusoidal Image                             Power Spectra                                  Phase Spectra                    Plot of Imaginary

D)     Here is the code we used:

// This macro creates a sine image

width = 512; height = 512;

xc = width/2; yc = height/2;

newImage("Sine wave", "32-bit black", width, height, 1);

for (y= 0; y<height; y++) {

for (x= 0; x<width; x++) {

setPixel(x, y, f1(x,y));

}

if (y%20==0) showProgress(y, height);

}                                                

//resetMinAndMax();

// makeLine(0, 0, width, height);

// run("Plot Profile");

exit;

function f0(x) {return 2*x*x-3;}

function f1(x,y) {return cos(x/4+y/5);}

function f2(x,y) {return sin(x/2+y/3)+sin(y/3);}

function f3(x) {return sqrt(x);}

function f4(x) {if (x==0) return 0; else return log(x);}

function f5(x) {return exp(x/100);}

Sinusoidal Image                             Power Spectrum

All these plots were pretty straight forward and show how Fourier analysis gives us information about the frequency content of images.

 

 

ECE 480 Lab 1

 Ryan Eslinger and Mike Fuson

 

Figure 1: Squares done using ImageJ

Figure 2: Arrows done using ImageJ

function illusion(rows, cols)

%ILLUSION Creates a famous optical illusion

% ILLUSION(ROWS, COLS) Allows user to specify illusion dimensions

%     (ROWS and COLS should be integers)

%

% Example:

%   illusion; %draws the illusion with 7 rows and 15 columns

%

% Example:

%   illusion(9,11); %draws the illusion with 9 rows and 11 columns

%

% Author: Joseph Kirk

% Email: jdkirk630 at gmail dot com

% Release: 1.3

% Release Date: 5/17/07

 

if nargin < 2

  rows = 7;

  cols = 15;

end

rows = max(3,ceil(abs(rows(1))));

cols = max(5,ceil(abs(cols(1))));

 

illusion = ones(rows,2*cols);

illusion(1:2:rows,3:4:2*cols) = 0;

illusion(:,2:4:2*cols) = 0;

illusion(2:2:rows,1:4:2*cols) = 0;

 

figure('Name','Optical Illusion','Numbertitle','off','Menubar','none');

axes('Units','normalized','Position',[.05 .05 .9 .85]);

imagesc(illusion);

colormap(gray); hold on

for r = 1/2:rows+1/2

  line([1/2 2*(cols+1)], [r r], 'color', 'b', 'linewidth', 2)

end

title(' Do the blue lines look parallel to you? ')

axis([1/2 2*cols+1/2 1/2 rows+1/2])

axis off; hold off

 

Figure 3: Optical illusion from internet compiled using previous MATLAB code

Figure 4: Optical illusion from internet

Conclusion: We completed the lab.