2010年11月18日 星期四

此因恰巧需擷取部分聲音信號,而使用GoldWave軟體,的範例說明,希望大家若有需對音源的信號進行修剪,有小小啟發。
修剪過程如下:
首先開取音源檔,GoldWave軟體幾乎大部分video皆可開啟,如下圖
因為立體聲所以有綠紅上下兩聲波頻道,下圖為其工具列:
我們將用下圖的幾個按鈕:
新增圖片 分別為"選擇區段刪除"、"選擇區段保留"、"選擇所看到的區段訊號"、"選擇全部訊號"、 "選擇區段設定"、"觀看全部訊號"(目前隱藏)、"觀看選擇區段"、"跳至前次觀看區段"、"放大"、"縮小"(目前隱藏)和"播放全部聲音訊號"、"播放選擇區段聲音訊號"、"接續播放聲音訊號"等作用。

大致選擇你想裁除或保留區段:作法大致作法有三
  1. 使用"選擇區段設定"按鍵,進行輸入選擇區段如下圖

  2. 使用滑鼠右鍵選擇開始標記和結束標記,標示選擇區段

  3. 在聲音圖上按下滑鼠左鍵不放,然後左移至選擇區段之最左端,再右移至選擇區段之最右端如下圖,最後放掉滑鼠左鍵,即可選擇。
選擇完成後如下圖 上圖中包含兩大區塊:上區塊為觀看區,下區塊為目前訊號全部狀態。

選擇完成後可以"觀看選擇區段"或"放大"按鍵再次觀看所選擇區段是否正確,若需修正可以滑鼠左鍵拉拖選擇區段之左端與右端。至於正確與否,可用"播放全部聲音訊號"和"播放選擇區段聲音訊號"按鍵聽取並搜尋,記下如前圖中播放時間軸的時間位置,再修正選擇區段及完成了區段選定。最後完成如下圖

上圖中之上區塊為全部觀看區段,藍色部分為選擇區段,黑色為未被選取區段,下區塊為全部訊號,而白色框線為觀看區段的標示區,可以滑鼠左鍵拉拖改變觀看區段大小。上下區塊皆可以滑鼠左鍵拉拖改變選擇區段大小。

最後再將選擇區段以"選擇區段刪除"或"選擇區段保留"按鍵刪除或保留、其餘刪除,如下圖刪除選擇區段。再進行存檔動作即可。















2010年11月15日 星期一

在數位信號處理的領域中,濾波器是一個重要的課題。而在Matlab的Signal Processing Toolbox™中,有一個工具,就是濾波器設計Filter Design and Analysis Tool (FDATool)。你只要在 MATLAB command視窗,輸入:
>>fdatool
即可開始一個圖形介面GUI displays,而預設濾波器default filter如下:
圖一


視窗中有三個區域,上半部包括了目前的濾波器的規格以及響應,上半部左邊是濾波器的性質,包括濾波器結構、階數、使用區段、是否穩定(the filter structure, order, number of sections used and whether the filter is stable or not)
上半部的右邊則是顯示各種濾波器的響應,如幅度、群延遲、濾波器係數等magnitude response, group delay and filter coefficients。
下半部則是互動式視窗,也就設計面板The Design Panel,可以定義濾波器的規格
例如設計一個低通濾波器,可以如下圖設定,但Density Factor是什麼呢?
Matlab的說明指出:The FIR Equiripple filter has a Density Factor option which controls the density of the frequency grid. Increasing the value creates a filter which more closely approximates an ideal equiripple filter, but more time is required as the computation increases.
我就使用了二種不同的設定,二種不同的設計結果,發現係數幾乎完全一樣(差距的數量級在10的負5次方),因此在結果上差異不大。
圖二-Density factor=16

圖三-Density factor=64

圖四和圖五是各自得到的濾波器響應,
無法分辨差異


那係數呢?如圖六,差別也很小,因此這個設定似乎不是很重要,就設一個中等的數字(幾十)就好了

2010年11月2日 星期二

JAVA影像處理程式設計系列 (一)影像直方圖(histogram)

影像的直方圖是以影像的像素值當橫座標,像素值出現的次數(或比例)當縱座標,所繪製的圖形。在影像分析上由直方圖可取得基本的分析資訊,彩色的影像可對RGB三種成分分別作直方圖分析,亦可先求出像素的平均值再作直方圖分析。本文中的程式包含兩個類別,PlotHistogram類別的功能是繪製直方圖,PlotHistogramTest類別內包含main()方法,主要是輸入及顯示影像、改變影像為Banded Sample Model(可固定影像格式,方便處理)及計算像素值出現的次數。(圖一)、(圖二)、(圖三)、(圖四)分別是輸入的原始影像及程式繪製的R、G、B直方圖,由藍色成分的直方圖可發現此張影像的藍色成分很少。還有,程式沒有作repaint處理,直方圖視窗請移到沒有被蓋住的地方,最小化後再最大化即會顯示。

//plot histogram
//constructor parameters as below:
//1.title
//2.H--histogram array;data type is int; H.length= 256
//3.max is the max value of H;data type is float
// only plot one band for each instance
import javax.swing.*;
import java.awt.*;
class PlotHistogram extends JFrame
{
int[] H=new int[256];
int max;
PlotHistogram(String title, int[] H, int max)
{
super(title);
this.H=H;
this.max=max;
setSize(600,450);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g); //call superclass's paint method
g.setColor(Color.white);
g.fillRect(0,0,600,450);
g.setColor(Color.black);
g.drawLine(50,50,50,400);
g.drawLine(50,400,550,400);
int width=600;
int height=450;
float stepX = (float) (width-100)/ (float)H.length;
float stepY = (float) (height-100 )/ (float) max;
for ( int i = 0; i < H.length; i++ )
{
int x = (int) ((float)i*stepX);
int y = (int) ((float)H[i]*stepY);
g.drawLine(x+50,400,x+50,height-50-y);
if(i%50==0)
{
String s=Integer.toString(i);
g.drawString(s,x+50,420);
}
}
}
}



import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import java.io.*;
import javax.media.jai.*;
import javax.media.jai.operator.*;
import javax.media.jai.widget.ScrollingImagePanel;
class PlotHistogramTest
{
public static void main(String args[])
{
int[][] histogram=new int[3][256];
int[] max={0,0,0};
// input original image
Scanner scanner= new Scanner(System.in);
System.out.println("Plase input the path and file name of the image file.");
String fileName = scanner.next();
RenderedOp img0 = JAI.create("fileload",fileName);
//display original image
JFrame f=new JFrame();
f.setTitle(fileName+"(original image)");
f.add(new ScrollingImagePanel(img0,img0.getWidth(),img0.getHeight()));
f.pack();
f.show();
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
//reformat image----image0 to image1
//BandedSampleModel, DataBuffer.TYPE_BYTE
int img1Width=img0.getWidth();
int img1Height=img0.getHeight();
ImageLayout layout=new ImageLayout();
layout.setSampleModel(new BandedSampleModel(DataBuffer.TYPE_BYTE,img1Width,img1Height,3));
RenderingHints rh=new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout);
RenderedOp img1=FormatDescriptor.create(img0,DataBuffer.TYPE_BYTE,rh);

//get pixel data from image 1
Raster ras1=img1.getData();
DataBuffer daBuf1=ras1.getDataBuffer();

//computing histogram
for(int i=0;i<3;i++) //initialize histogrsm with 0
for(int j=0;j<256;j++)
histogram[i][j]=0;

for(int bank=0; bank<3; bank++)
for(int i=0;i for(int j=0;j {
int g=daBuf1.getElem(bank,i*img1Width+j);
histogram[bank][g]=histogram[bank][g]+1;
}
//plot histogram---using "plotHistogram class"
//looking for the max value
for(int bank=0; bank<3; bank++)
for (int g=0; g< 256; g++)
{
if (histogram[bank][g]>max[bank])
max[bank]=histogram[bank][g];
}
//building R, G, B plotHistogram instance
PlotHistogram plotRed=new PlotHistogram("histogram-RED",histogram[0],max[0]);
PlotHistogram plotGREEN=new PlotHistogram("histogram-GREEN",histogram[1],max[1]);
PlotHistogram plotBLUE=new PlotHistogram("histogram-BLUE",histogram[2],max[2]);
}
}













2010年11月1日 星期一