Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 19 Chapter 13 Images continued. Outline from Chapter 12 -1 13.4 Operating on Images.

Similar presentations


Presentation on theme: "Lecture 19 Chapter 13 Images continued. Outline from Chapter 12 -1 13.4 Operating on Images."— Presentation transcript:

1 Lecture 19 Chapter 13 Images continued

2 Outline from Chapter 12 -1 13.4 Operating on Images

3 Modifying an Image Locating an image within another image – Scene – Place an object into the scene scene = imread ('C:\Documents and Settings\All Users\Documents\My Pictures \Sample Pictures\Water lilies.jpg'); image(scene); %bumblebee? bee1 = imread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009 \bee1.jpg'); image(bee1); beeSize = 75; clippedBee1 = bee1(1:beeSize, 1:beeSize, :); image(clippedBee1); %initialize scene beeInScene = scene; beeInScene(1:beeSize, 1:beeSize, :) = clippedBee1; image(beeInScene)

4 Rotating an Image %rotate the bee, around the center of the image rotatedBee = clippedBee1; for theta = linspace(0,-pi/2,4) for xBee = 1:beeSize for yBee = 1:beeSize centeredX = xBee-beeSize/2; centeredY = yBee-beeSize/2; newCenteredCoordinatesBee = rotation2D(theta)*[centeredX centeredY]'; newCoordinatesBee = newCenteredCoordinatesBee + beeSize/2 newCoordinatesBee = round(newCoordinatesBee); if newCoordinatesBee(1)<1 newCoordinatesBee(1) = 1; end; if newCoordinatesBee(2)<1 newCoordinatesBee(2) = 1; end; if newCoordinatesBee(1)>beeSize newCoordinatesBee(1) = beeSize; end; if newCoordinatesBee(2)>beeSize newCoordinatesBee(2) = beeSize; end; rotatedBee(newCoordinatesBee(1,1), newCoordinatesBee(2,1), :) = clippedBee1(xBee, yBee, :); end beeInScene = scene; beeInScene(lastXlocs, lastYlocs, :) = rotatedBee; image(beeInScene) pause(.1) end

5 Setting a Region within an Image for time = t x = 8*time; y = 5*time; xlocations = round((1:beeSize)+x); ylocations = round((1:beeSize)+y); beeInScene = scene; beeInScene(xlocations, ylocations, :) = clippedBee1; image(beeInScene) pause(.05) lastXlocs = xlocations; lastYlocs = ylocations; end

6 Color Adjustment Via Mask Use the image to develop a logical array Use the logical array as a mask Update the image where mask allows

7 Green in Moth We can use the combination of the presence of high level of green with the lower levels of red and blue, to identify the moth, e.g., >150.

8 Develop the Mask mask(mothSize,mothSize,3) = 0; %establish size, mask(:,:,3) = 0; %no changes to blue, yet mask(:,:,1) = 0; %no changes to red, yet mask(:,:,2) = clippedMoth1(:,:,2)>greenThreshold... & clippedMoth1(:,:,1)<redThreshold... & clippedMoth1(:,:,3)<blueThreshold; %if the green is > threshold, and blue and red are below theirs %then allow green level at that pixel to change

9 Apply the Mask greenerMoth = clippedMoth1; greenerMoth(mask) = uint8(255); mask(:,:,3)=mask(:,:,2);% transfer the locations to the blue signal mask(:,:,2)= 0; %leave green alone greenerMoth(mask) = uint8(0); %no blue mask(:,:,1)=mask(:,:,3); %transfer the locations to the red signal mask(:,:,3)=0; %leave the blue alone greenerMoth(mask) = uint8(0); %no red image(greenerMoth)

10 Enhanced Green

11 Find Yellow Edges

12 Arithmetic with Colors yellow = gr + red; plot(red, 'r'); hold on plot(gr, 'g'); plot(bl, 'b'); plot(yellow, 'y');

13 More Arithmetic with Colors rat = yellow./ bl; subplot(2,1,2) plot(rat,'--k'); Maybe 2.5 has meaning as a threshold; maybe 3.5

14 Edge Detection in Color

15 Outline from Chap 14 14.1 Physics of Sound 14.2 Recording and Playback 14.3 MATLAB Implementation 14.4 Time Domain Operations – 14.4.1 Slicing and Concatenating Sound – 14.4.2 Musical Background – 14.4.3 Changing Sound Frequency Poorly – 14.4.4 Changing Sound Frequency Well

16 Physics of Sound Dynamic range: soft sounds and loud sounds have significantly different levels, so a logarithmic scale is used Frequencies serve as a basis set for describing waveforms. Spectral decomposition is extremely useful.

17 Recording and Playback Capturing the dynamic range: many significant bits – Approximately softest sound is 10 billion times softer than the loudest comfortable sound – 16 bits is popular Capturing the high frequency content: high enough sampling rate. – Highest frequency heard said to be 20 kiloHertz – Sample at twice that suggests 40 kHz

18 In MATLAB -1 Read with – Wavread for.wav files – Auread for.au files – [Y,FS,NBITS]=WAVREAD(FILE) returns the sample rate (FS) in Hertz and the number of bits per sample (NBITS) used to encode the data in the file. [b16, F16, n] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\chimes.wav'); sound(b16, F16) [bb16, FF16, n] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\ding.wav'); sound(bb16, FF16) [bbb16, FFF16, n] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\tada.wav'); sound(bbb16, FFF16)

19 In MATLAB -2 Concatenation longSound = [b16; bb16; bbb16]; sound(longSound,FFF16)

20 In MATLAB -3 Examining the time domain waveform

21 In MATLAB - 4 Selecting in the time domain piece1Start = round(length(b16)*(1/4)); piece1End = round(length(b16)*(3/4)); piece1 = b16(piece1Start:piece1End,:);

22 Modify Frequency by Resampling Here the Resampling Is by Subset [piano, piano16, n3] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\piano.wav'); sound(piano, piano16) note = piano; half = 2^(1/12); whole = half^2; for index = 1:8 sound(note, piano16); pause(.5); if (index==3)||(index ==7) mult = half; else mult = whole; end note = note(ceil(1:mult:end)); end; File from http://chronos.ece.mismi.edu/~dasp/samples/samples.html

23 Frequency Domain Different from time domain Express our time waveform as a sum of other, simpler time waveforms. f(t) = sum of sin and cos functions, each with an amplitude, and a frequency. Then we can modify the amplitudes of the individual sins and cosines, where the modification depends upon the frequency, to obtain useful effects (like taking the hissy noise out of damaged records).

24 Waveform Composition An algorithm, the fast Fourier Transform (FFT), calculates the coefficients of the components of the decomposition of a time-domain waveform. Each frequency used in the decomposition has a coefficient. If the coefficients are plotted vs. frequency, that is a spectrum.

25 In MATLAB FFT operates on time domain to generate frequency component coefficients. iFFT operates on frequency domain coefficients to generate time domain representation.

26 Example Using FFT dt = 1/400; pts = 10000; f = 8; t = (1:pts)*dt; %sampling times x1 = sin(2*pi*f*t); x2 = 3*sin(2*pi*5*f*t); x3 = 7*sin(2*pi*11*f*t); x=x1+x2+x3; subplot (3,1,1) plot(t(1:end/25),x(1:end/25)); title('Time Domain Sine Waves'); ylabel('Amplitude'); xlabel('Time (Sec)'); Y =fft(x); %Y gets the coefficients df = 1/ t(end); %the frequency spacing fmax = df * pts /2; f = (1:pts)*2*fmax/pts; %frequencies subplot(3,1,2); plot(f, real(Y)); title('Real Part'); xlabel('Frequency (Hz)'); ylabel('Energy'); subplot(3,1,3); plot(f, imag(Y)); title('Imaginary Part'); xlabel('Frequency (Hz)'); ylabel('Energy');

27 Comparing the Timbre of Instruments

28 Code for Previous disp('starting timbre') [trumpet, F16, n1] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\trumpet.wav'); sound(trumpet, F16) %F16 ptsTrumpet = length(trumpet); [cello, FF16, n2] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\cello.wav'); sound(cello, FF16) %FF16 ptsCello = length(cello); [piano, FFF16, n3] = wavread('C:\Documents and Settings\therese\My Documents\CSE1100summer2009\piano.wav'); sound(piano, F16) %FFF16 ptsPiano = length(piano); dtTrumpet = 1/F16; dtCello = 1/FF16; dtPiano = 1/FFF16; f = 8; tTrumpet = (1:ptsTrumpet)*dt; %sampling times tCello = (1:ptsCello)*dt; %sampling times tPiano = (1:ptsPiano)*dt; %sampling times pause(tcello(ptsCello)); subplot (3,1,1) plot(tTrumpet(1:round(end/25)),trumpet(1:round(end/25)),' y'); hold on plot(tCello(1:round(end/25)),cello(1:round(end/25)),'r'); plot(tPiano(1:round(end/25)),piano(1:round(end/25)),'g'); title('Time Domain Trumpet'); ylabel('Amplitude'); xlabel('Time (Sec)'); Ytrumpet =fft(trumpet); %Y gets the coefficients Ycello = fft(cello); Ypiano = fft(piano); dfTrumpet = 1/ tTrumpet(end); %the frequency spacing dfCello = 1/ tCello(end); %the frequency spacing dfPiano = 1/ tPiano(end); %the frequency spacing fmaxTrumpet = dfTrumpet * ptsTrumpet /2; fmaxCello = dfCello * ptsCello /2; fmaxPiano = dfPiano * ptsPiano /2; fTrumpet = (1:ptsTrumpet)*2*fmaxTrumpet/ptsTrumpet; %frequencies fCello = (1:ptsCello)*2*fmaxCello/ptsCello; %frequencies fPiano = (1:ptsPiano)*2*fmaxPiano/ptsPiano; %frequencies subplot(3,1,2); plot(fTrumpet, real(Ytrumpet),'y'); hold on plot(fCello, real(Ycello),'r'); plot(fPiano, real(Ypiano),'g'); title('Real Part'); xlabel('Frequency (Hz)'); ylabel('Energy');

29 More Code subplot(3,1,3); plot(fTrumpet, imag(Ytrumpet)); hold on plot(fCello, imag(Ycello),'r'); plot(fPiano, imag(Ypiano),'g'); title('Imaginary Part'); xlabel('Frequency (Hz)'); ylabel('Energy');


Download ppt "Lecture 19 Chapter 13 Images continued. Outline from Chapter 12 -1 13.4 Operating on Images."

Similar presentations


Ads by Google