王寧邦 徐博 夏百川 夏娜 邰永航 李瓊



摘 要: 固定資產清查是高校、企事業、科研院所等的一項例行性工作,資產清查過程中一般要求對固定資產拍照存檔。資產清查收集到的資產圖片保存至文件夾,其中有成千上萬張資產圖片,需要從中挑出來一部分資產圖片丟棄,且需要被挑出來的資產有圖有真相地存放在其它文件夾,同時2個文件夾中資產圖片文件名、清晰度、大小等均不一,針對如何快速完成這個圖片文件挑選過程,文中提出一種基于顏色直方圖的資產圖片相似度統計核對算法,并對其過程進行了驗證,證明了算法的有效性。
關鍵詞: 資產清查;顏色直方圖;圖片相似度
Abstract:Fixed assets inventory is a routine work in colleges and universities enterprise and institution research institutes etc.. In the process of asset inventory it is generally required to take photos of fixed assets.There are thousands of images in the asset-image file collected by asset assessment. As required part of the assets should be picked out and these picked assets need to be put into another file meanwhile its asset images in two folders have different file name definition and size. Aiming at how to complete the process quickly this paper puts forward the algorithm based on color histogram for gathering statistics and checking asset image similarity. After that the process is verified and the effectiveness of the algorithm is also proved.
Key words: asset inventory;color histogram;picture similarity
引言
隨著多媒體技術及Internet技術的迅速發展 各行各業對圖像的使用日益廣泛 圖像信息資源的管理和檢索也越發重要。通過手工標記和索引圖像的傳統方法已經難以滿足現實需求,因而亟待設計推出有效研發方法。目前,顏色直方圖的應用研究普遍存在于圖像檢索、目標跟蹤粒子濾波[1]、遙感等各個領域。其中,王向陽[2]等人基于視覺權值的分塊顏色直方圖圖像相似度計算提出了一種新方法用于圖像檢索;姜蘭池[3]等也發表了一種新的基于HSV非均勻量化分塊顏色直方圖的圖像檢索方法;胡屹群[4]等人結合視覺詞袋模型和顏色直方圖探討給出了一種遙感影像檢索方法;張俊杰[5]等人利用顏色直方圖進行二次識別實現了排除誤檢區域和敵我識別雙重功能;邵建荃[6]將顏色直方圖、SURF特征、時間信息三者相結合進行車輛跟蹤。
固定資產清查是高校、企事業、科研院所等部門的一項常規例行性工作,資產清查過程中一般要求對固定資產拍照存檔。資產清查將收集到的資產圖片保存至文件夾,其數目甚至可達成千上萬張,需要從中挑選出一部分資產圖片,且將這部分資產圖片及詳情資料存放在其它文件夾,與此同時2個文件夾中資產圖片文件名、清晰度、大小等均為不一。針對如何減少人工消耗并明顯縮短圖片文件挑選過程時間,文中設計提出了一種基于顏色直方圖相似度計算的資產圖片核對算法。
1 顏色直方圖的相似度計算方法原理
通過將原始圖像與待比較圖像的像素數據進行采集,生成特定的直方圖數據,運用巴氏系數[7-10](Bhattacharyya coefficient)算法,計算出2個圖像的相似程度,數值在[0 1]之間,0表示極其不同,1表示極其相似(相同)。
1.1 直方圖計算
文中采用的是單一直方圖,每個顏色的值范圍為0 ~ 255。假定將顏色分為一定范圍等份,如果分為16等份的話,此時每個等份值范圍為16,再假設RGB值為(14 68 221),16等份后,其所對應直方圖索引值(index)分別為: (0 4 13)。研究推得,索引值的計算公式為:
1.2 巴氏系數計算
巴氏系數[3]數學運算公式為:
其中,p p′分別表示原始與待比較的圖像直方圖數據,對2個圖像中的每一個第i部分數據點相乘后進行開平方再相加得到的值就是圖像相似度值。
2 資產核對算法設計流程與實現
2.1 算法流程
(1)初始化待處理數據源、比較數據源、目標數據結果。
(2)分析處理內容為:
① 提取待處理數據源中一張圖片,與目標數據源進行圖像匹配,達到設定閾值的圖片便是目標數據,將該目標文件復制到指定文件夾;
②如果待處理數據源資產還未為空,則循環執行 ①。
2.2 實現過程
(1)開始;讀取文件(待處理圖片文件、比較對象圖片文件)路徑。
(2)打開待處理圖片文件。
(3)打開比較對象圖片文件。
(4)比較2張圖片相似度。
(5)將比較結果提供一定處理:復制、刪除等。
(6)循環以上讀取到復制的過程;結束。
2.3 重點程序代碼設計
(1)核心代碼處理。研發代碼如下:
String fileurl = "C:\\Tepfile\\backgrounds";
String fileurl2 = "C:\\Tepfile\\image";
ArrayList
ArrayList
for (int i = 0;i < anArray.size();i++) {
try {
sourceImage = null;
sourceImage = ImageIO.read(new File InputStream(anArray.toArray()[i].toString()));
this.repaint();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
repaint();
for (int i1 = 0;i1 < anArray2.size();i1++) {
try {
candidateImage = null;
candidateImage = ImageIO.read(new FileInputStream(anArray2.toArray()[i1].toString()));
ImageComparer imageCom = new Image Comparer(sourceImage,candidateImage);
similarity = imageCom.modelMatch();
System.out.println(similarity);
this.repaint();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
(2)相似度計算。研發代碼可見如下:
public double modelMatch() {
HistogramFilter hfilter = new HistogramFilter();
float[] sourceData = hfilter.filter(source Image null);
float[] candidateData = hfilter.filter(candidate Image null);
double[] mixedData = new double[source Data.length];
for(int i=0;i mixedData[i] = Math.sqrt(sourceData[i] * candidateData[i]); } double similarity = 0; for(int i=0;i similarity += mixedData[i]; } return similarity; } (3)直方圖數據采集。實現時可運行如下代碼: public float[] filter(BufferedImage src BufferedImage dest) { int width = src.getWidth(); int height = src.getHeight(); int[] inPixels = new int[width*height]; float[] histogramData = new float[redBins * greenBins * blueBins]; getRGB( src 0 0 width height inPixels ); int index = 0; int redIdx = 0 greenIdx = 0 blueIdx = 0; int singleIndex = 0; float total = 0; for(int row=0;row int ta = 0 tr = 0 tg = 0 tb = 0; for(int col=0;col index = row * width + col; ta = (inPixels[index] >> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff;
tg = (inPixels[index] >> 8) & 0xff;
tb = inPixels[index] & 0xff;
redIdx = (int)getBinIndex(redBins tr 255);
greenIdx = (int)getBinIndex (greenBins tg 255);
blueIdx = (int)getBinIndex(blueBins tb 255);
singleIndex = redIdx + greenIdx * redBins + blueIdx * redBins * greenBins;
histogramData[singleIndex] += 1;
total += 1;
}
}
for (int i = 0;i < histogramData.length;i++)
{
histogramData[i] = histogramData[i] / total;
}
return histogramData;
}
private float getBinIndex(int binCount int color int colorMaxValue) {
float binIndex = (((float)color)/ ((float) colorMaxValue)) * ((float)binCount);
if(binIndex >= binCount)
binIndex = binCount- 1;
return binIndex;
}
public int[] getRGB( BufferedImage image int x, int y, int width, int height int[] pixels ) {
int type = image.getType();
if ( type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )
return (int [])image.getRaster().getDataElements( x y width height pixels );
return image.getRGB( x y width height pixels 0 width );
}
3 算法驗證
過程處理的運行界面如圖1所示。
顏色直方圖是在許多圖像檢索系統中已獲得廣泛采用的顏色特征,算法簡單方便,經過多次試驗,如圖1中相似度為0.955 325 295 373 811 1的情況,是由于2個資產的色調高度相同所致,所以研究將最高閾值設置為大于等于0.999 999 99,即只有相似度到達這個數值,才會判定為是2個相同的資產。閾值的設定需要自定義。
實驗模擬從16張資產圖片中挑選出7張,相似度計算數值如圖2所示,可見其中有一張相似度近似為1滿足丟棄的要求。
資產圖片相似度計算過程耗時則如圖3所示。
4 結束語
文中針對國有資產清查事件中遇到的圖片核對過程工作量大等特點,設計提出了基于顏色直方圖相似度計算的資產核對算法。首先分析探討顏色直方圖的基礎算法原理,而后論述了文中研發的算法流程和實現過程,最后則對算法的應用進行了有效性驗證。雖然顏色直方圖算法簡單、應用普遍,也高效達成了預期研究指定的資產清查圖片核對的任務內容,但是相似度計算過程表現出耗時長的特點,這是接下來可以進一步研究和改進的方向。
參考文獻
[1] 陶立超,趙宇明. 基于分塊顏色直方圖和粒子濾波的物體跟蹤[J]. 計算機工程與應用,2012,48(7):165-168.
[2] 王向陽,楊紅穎,鄭宏亮,等. 基于視覺權值的分塊顏色直方圖圖像檢索算法[J]. 自動化學報,2010(10):1489-1492.
[3] 姜蘭池,沈國強,張國煊. 基于HSV分塊顏色直方圖的圖像檢索算法[J]. 機電工程,2009,26(11):54-57.
[4] 胡屹群,周紹光,岳順,等. 利用視覺詞袋模型和顏色直方圖進行遙感影像檢索[J]. 測繪通報,2017(1):53-57.
[5] 張俊杰,丁淑艷,李倫波. 基于類Haar特征和顏色特征的NAO機器人識別[J]. 計算機與現代化,2017(2):30-35.
[6] 邵建荃. 非重疊場景下多攝像機車輛跟蹤研究[J]. 現代計算機(專業版),2017(2):49-53.
[7] BHATTACHARYYA A. On a measure of divergence between two statistical populations defined by their probability distributions[J]. Bulletin of the Calcutta Mathematical Society,1943,35: 99-109.
[8] 王寧邦,劉江濤,梁紅飛,等. Cacti在可視化校園網絡管理中的應用[J]. 云南民族大學學報(自然科學版),2018,27(2):129-130.
[9] 王寧邦,徐博. 一種桌面門戶移動化解決方法[J]. 昆明冶金高等專科學校學報,2017,33(3):53-58.
[10]徐博,王寧邦,陳彬,等. 網絡設備故障解決一體化平臺初探[J]. 網絡安全技術與應用,2016(8):24,26.