001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.workinprogress.accel; 031 032import java.io.File; 033import java.io.IOException; 034 035import org.openimaj.image.FImage; 036import org.openimaj.image.ImageUtilities; 037import org.openimaj.image.processing.algorithm.FourierTransform; 038 039import edu.emory.mathcs.jtransforms.fft.FloatFFT_3D; 040 041public class VideoSpectrogram { 042 public static void main(String[] args) throws IOException { 043 final FImage[] sequence = new FImage[20]; 044 for (int i = 0; i < sequence.length; i++) { 045 sequence[i] = ImageUtilities.readF(new File("/Users/jon/pendulum+circle+notexture/frame_" + i + ".png")); 046 } 047 048 final int width = sequence[0].width; 049 final int height = sequence[0].height; 050 051 final int windowSize = 10; 052 final float[][][][] spectrogram = new float[sequence.length - windowSize][][][]; 053 054 for (int w = 0; w < spectrogram.length; w++) { 055 final FloatFFT_3D fft = new FloatFFT_3D(windowSize, height, width); 056 final float[][][] data = new float[10][][]; 057 for (int i = 0; i < windowSize; i++) 058 data[i] = FourierTransform.prepareData(sequence[i], height, width, false); 059 fft.complexForward(data); 060 061 spectrogram[w] = data; 062 } 063 064 for (int i = 1; i < spectrogram.length - 2; i++) { 065 for (int j = 1; j < spectrogram[0].length - 2; j++) { 066 for (int k = 1; k < spectrogram[0][0].length - 2; k++) { 067 for (int l = 1; l < (spectrogram[0][0][0].length / 2) - 2; l++) { 068 final float centre = (float) Math.sqrt(spectrogram[i][j][k][l * 2] * spectrogram[i][j][k][l * 2] 069 + spectrogram[i][j][k][l * 2 + 1] * spectrogram[i][j][k][l * 2 + 1]); 070 boolean max = true; 071 072 for (int ii = -1; ii <= 1; ii++) { 073 for (int jj = -1; jj <= 1; jj++) { 074 for (int kk = -1; kk <= 1; kk++) { 075 for (int ll = -1; ll <= 1; ll++) { 076 if (i != 0 && j != 0 && k != 0 && l != 0) { 077 final float curr = (float) Math 078 .sqrt(spectrogram[i + ii][j + jj][k + kk][(l + ll) * 2] 079 * spectrogram[i + ii][j + jj][k + kk][(l + ll) * 2] 080 + spectrogram[i + ii][j + jj][k + kk][(l + ll) * 2 + 1] 081 * spectrogram[i + ii][j + jj][k + kk][(l + ll) * 2 + 1]); 082 083 if (curr > centre) { 084 max = false; 085 } 086 } 087 } 088 } 089 } 090 } 091 092 if (max) 093 System.out.println("max " + i + " " + j + " " + k + " " + l); 094 } 095 } 096 } 097 } 098 } 099}