2012-12-28 84 views
3

我有以下問題: 我給了一組圖像,我需要用OpenCV庫的方式將它們劃分爲照片和圖片(圖形)如何區分照片和圖片?

我已經嘗試過

  1. 分析RGB柱狀圖(平均圖像具有直方圖的空箱),
  2. 分析HSV直方圖(在平均圖像已經沒有太多的顏色),
  3. 搜索輪廓(平均而言,圖片上的輪廓數量少於照片上的數量)。

所以我有7%的錯誤(2000圖像測試)。我有點困惑,因爲我沒有很多計算機視覺方面的經驗。

例如,下面這張照片。它的直方圖(RGB和HSV)非常差,輪廓數量很小。此外還有很多背景顏色,所以我需要找到一個對象來計算它的直方圖(我使用findContours())。但無論如何,我的算法檢測到此圖像爲圖片

photo 1

而且多了一個例子:

photo 2

問題與圖片是噪音。我有小尺寸(200 * 150)的圖像,並且在某些情況下,噪點非常明顯,我的算法會將此圖像檢測爲照片。我試圖模糊圖像,但在這種情況下,顏色的數量會因爲混合像素而增加,並且會減少輪廓的數量(一些較暗的邊界變得難以區分)。圖片

例子: picture 1 picture 2

我也試過色彩分割和MSER,但是我最好的結果仍然是7%。

你能告訴我我可以嘗試什麼方法嗎?

+0

那麼什麼區別從圖片中的照片?對象的數量? – Blender

+0

我得出結論,他們之間的主要區別是顏色的數量。但是,正如我在前面的問題中所展示的,照片也可以具有少量的顏色......在大多數情況下,照片的邊緣並不多。但它也不是一個羅爾。 –

+1

你是否嘗試過一些機器學習方法,如決策樹,邏輯迴歸,神經網絡?我認爲你必須僱用其中的一些方法來更好地解決這個n維問題。你可以發佈數據集,以便任何人都可以嘗試提出更好的解決方案嗎? –

回答

3

我用你的數據集來創建真正簡單的模型。爲此,我在R中使用了Rattle庫。

輸入數據

rgbh1 - number of bins in RGB histogram, which value > @[email protected], in my case @[email protected] = 30 (340 is maximum value) 
rgbh2 - number of bins in RGB histogram, which value > 0 (not empty) 
hsvh1 - number of bins in HSV histogram, which value > @[email protected], in my case @[email protected] = 30 (340 is maximum value) 
hsvh2 - number of bins in HSV histogram, which value > 0 (not empty) 
countours - number of contours on image 
PicFlag - flag indicating picture/photo (picture = 1, photo = 0) 

數據探索

爲了更好地瞭解您的數據,這裏是圖片/照片組獨立變量的分佈圖(有關於y軸的百分比):

enter image description here

它清楚地表明,有潛在的力量變量。他們中的大多數都可以在我們的模型中使用。接下來,我已經創建了簡單的散點圖矩陣看到一些變量組合是否可能是有用的:

enter image description here

你可以看到countours數量的例如組合rgbh1看起來很有希望。

在下面的圖表中,您可以注意到變量之間也存在很強的相關性。 (一般來說,我們希望有很多變量具有較低的相關性,而只有有限數量的相關變量)。餅圖顯示有多大的相關性 - 充分圓圈表示1,空圓圈表示0,我的意見是,如果相關性超過.4可能不是好主意,在這個模型中兩個變量)

enter image description here

模型

然後我使用決策樹,隨機森林,邏輯迴歸和神經網絡創建簡單的模型(保持拉特爾的默認)。作爲輸入,我已經使用60/20/20分割(訓練,驗證,測試數據集)的數據。這是我的結果(請參閱谷歌,如果你不明白錯誤矩陣):

Error matrix for the Decision Tree model on pics.csv [validate] (counts): 

     Predicted 
Actual 0 1 
    0 167 22 
    1 6 204 

Error matrix for the Decision Tree model on pics.csv [validate] (%): 

     Predicted 
Actual 0 1 
    0 42 6 
    1 2 51 

Overall error: 0.07017544 

Rattle timestamp: 2013-01-02 11:35:40 
====================================================================== 
Error matrix for the Random Forest model on pics.csv [validate] (counts): 

     Predicted 
Actual 0 1 
    0 170 19 
    1 8 202 

Error matrix for the Random Forest model on pics.csv [validate] (%): 

     Predicted 
Actual 0 1 
    0 43 5 
    1 2 51 

Overall error: 0.06766917 

Rattle timestamp: 2013-01-02 11:35:40 
====================================================================== 
Error matrix for the Linear model on pics.csv [validate] (counts): 

     Predicted 
Actual 0 1 
    0 171 18 
    1 13 197 

Error matrix for the Linear model on pics.csv [validate] (%): 

     Predicted 
Actual 0 1 
    0 43 5 
    1 3 49 

Overall error: 0.07769424 

Rattle timestamp: 2013-01-02 11:35:40 
====================================================================== 
Error matrix for the Neural Net model on pics.csv [validate] (counts): 

     Predicted 
Actual 0 1 
    0 169 20 
    1 15 195 

Error matrix for the Neural Net model on pics.csv [validate] (%): 

     Predicted 
Actual 0 1 
    0 42 5 
    1 4 49 

Overall error: 0.0877193 

Rattle timestamp: 2013-01-02 11:35:40 
====================================================================== 

結果

正如你所看到的6.5%和8%之間的總體誤差率oscilates。我不認爲通過調整使用的方法的參數可以顯着提高此結果。有兩種方法如何降低總體誤差率:

  • 添加更多不相關的變量(我們通常有100+的建模數據集的輸入變量和+/- 5-10是在最後的模型)
  • 添加更多的數據(我們可以再調整模型不受過度擬合被嚇)

使用sofware:

代碼用於創建corrgram和散點圖(使用嘎嘎GUI產生其他輸出):

# install.packages("lattice",dependencies=TRUE) 
# install.packages("car") 

library(lattice) 
library(car) 

setwd("C:/") 

indata <- read.csv2("pics.csv") 

str(indata) 


# Corrgram 
corrgram(indata, order=TRUE, lower.panel=panel.shade, 
     upper.panel=panel.pie, text.panel=panel.txt, 
     main="Picture/Photo correlation matrix") 

# Scatterplot Matrices 
attach(indata) 
scatterplotMatrix(~rgbh1+rgbh2+hsvh1+hsvh2+countours|PicFlag,main="Picture/Photo scatterplot matrix", 
        diagonal=c("histogram"),legend.plot=TRUE,pch=c(1,1)) 
1

那麼一般的建議是增加特徵的數量(或獲得更好的特徵),並使用這些特徵構建一個分類器,並使用適當的機器學習算法進行訓練。 OpenCV已經有一些好的machine learning算法,您可以使用它們。

我從來沒有處理過這個問題,但一個快速的谷歌搜索引導我到Cutzu的這篇論文et。人。Distinguishing paintings from photographs

+0

謝謝!我肯定會嘗試機器學習,因爲我想,沒有它就很難找到最佳解決方案。我讀過這些文章,所以大部分都是我從他們身上取得的想法。 –

1

應該有用的一個功能是梯度直方圖。自然圖像具有特定的梯度強度分佈。

相關問題