2015의 게시물 표시

[Octave] Radon Transform function

function PR = radon(IMG, THETA) %% This MATLAB function takes an image matrix and vector of angles and then %% finds the 1D projection (Radon transform) at each of the angles. It returns %% a matrix whose columns are the projections at each angle. %% %% Written by : Justin K. Romberg % pad the image with zeros so we don't lose anything when we rotate. [iLength, iWidth] = size(IMG); iDiag = sqrt(iLength^2 + iWidth^2); LengthPad = ceil(iDiag - iLength) + 2; WidthPad = ceil(iDiag - iWidth) + 2; padIMG = zeros(iLength+LengthPad, iWidth+WidthPad); padIMG(ceil(LengthPad/2):(ceil(LengthPad/2)+iLength-1), ... ceil(WidthPad/2):(ceil(WidthPad/2)+iWidth-1)) = IMG; % loop over the number of angles, rotate 90-theta (because we can easily sum % if we look at stuff from the top), and then add up. Don't perform any % interpolation on the rotating. n = size(padIMG,1); x = linspace(-1,1,n); [X1,Y1] = meshgrid(x,x); n = length(THETA); PR = zeros(size(padIMG,2), n); for i = 1:n thet...

[Octave] feature_spectral_flux

function F = feature_spectral_flux(windowFFT, windowFFTPrev) % function F = feature_spectral_flux(windowFFT, windowFFTPrev) % % Computes the spectral flux feature % ARGUMENTS: % - windowFFT: the abs(FFT) of the current audio frame % (computed by getDFT() function) % - windowFFTPrev: the abs(FFT) of the previous frame % % RETURNS: % - F: the spectral flux value for the input frame % % normalize the two spectra: windowFFT = windowFFT / sum(windowFFT); windowFFTPrev = windowFFTPrev / sum(windowFFTPrev+eps); % compute the spectral flux as the sum of square distances: F = sum((windowFFT - windowFFTPrev).^2);

[Octave] feature_spectral_centroid

function [C,S] = feature_spectral_centroid(window_FFT, fs) % function C = feature_spectral_centroid(window_FFT, fs) % % Computes the spectral centroid and spread of a frame % % ARGUMENTS: % - window_FFT: the abs(FFT) of an audio frame % (computed by getDFT() function) % - fs: the sampling freq of the input signal (in Hz) % % RETURNS: % - C: the value of the spectral centroid % (normalized in the 0..1 range) % - S: the value of the spectral spread % (normalized in the 0..1 range) % % number of DFT coefs windowLength = length(window_FFT); % sample range m = ((fs/(2*windowLength))*[1:windowLength])'; % normalize the DFT coefs by the max value: window_FFT = window_FFT / max(window_FFT); % compute the spectral centroid: C = sum(m.*window_FFT)/ (sum(window_FFT)+eps); % compute the spectral spread S = sqrt(sum(((m-C).^2).*window_FFT)/ (sum(window_FFT)+eps)); % normalize by fs/2 % (so that 1 correponds to the maximum...

[Octave] feature_spectral_rolloff

function mC = feature_spectral_rolloff(windowFFT, c) % function mC = feature_spectral_rolloff(windowFFT, c) % % Computes the spectral rolloff feature. % ARGUMENTS: % - windowFFT: the abs(FFT) of the current audio frame % (computed by getDFT() function) % - c: the spectral rolloff parameter % % RETURNS: % - mC: the spectral rolloff value for the input frame % % compute total spectral energy: totalEnergy = sum(windowFFT.^2); curEnergy = 0.0; countFFT = 1; fftLength = length(windowFFT); % find the spectral rolloff as the frequency position where the % respective spectral energy is equal to c*totalEnergy while ((curEnergy<=c*totalEnergy) && (countFFT<=fftLength)) curEnergy = curEnergy + windowFFT(countFFT).^2; countFFT = countFFT + 1; end countFFT = countFFT - 1; % normalization: mC = ((countFFT-1))/(fftLength);

[Octave] feature_spectral_entropy

function En = feature_spectral_entropy(windowFFT, numOfShortBlocks) % function En = feature_spectral_entropy(windowFFT, numOfShortBlocks) % % This function computes the spectral entropy of the given audio frame % % ARGUMENTS: % - windowFFT: the abs(FFT) of an audio frame % (computed by getDFT() function) % - numOfShortBins the number of bins in which the spectrum % is divided % % RETURNS: % - En: the value of the spectral entropy % % number of DFT coefs fftLength = length(windowFFT); % total frame (spectral) energy Eol = sum(windowFFT.^2); % length of sub-frame: subWinLength = floor(fftLength / numOfShortBlocks); if length(windowFFT)~=subWinLength* numOfShortBlocks windowFFT = windowFFT(1:subWinLength* numOfShortBlocks); end % define sub-frames: subWindows = reshape(windowFFT, subWinLength, numOfShortBlocks); % compute spectral sub-energies: s = sum(subWindows.^2) / (Eol+eps); % compute spectral entropy: En = -sum(...

Processing + OpenCV + FFT motion detection

import hypermedia . video .*; // Imports the OpenCV library import java . awt . Rectangle ; import ddf . minim . analysis .*; import ddf . minim .*; OpenCV opencv ; // Creates a new OpenCV object Minim minim ; AudioInput in ; FFT fft ; int w ; PImage fade ; PImage movementImg ; // Creates a new PImage to hold the movement image ArrayList bubbles ; // Creates an ArrayList to hold the Bubble objects PImage bubblePNG ; // Creates a PImage that will hold the image of the bubble int randPos ; PImage fishImg ; PImage fishImg2 ; PImage fishImg3 ; PImage fishImg4 ; PImage fishImg5 ; PImage sharkImg ; PImage clockImg ; PImage backImg ; int sharkX = 480 ; int sharkY = height / 2 ; int sharkMoves = 480 ; int sharkSpeed = 40 ; int flagForShark = 0 ; int flagForNotification = 0 ; ArrayList psystems ; int NotificationX = 10 ; int No...