2017-02-07 7 views
1

私はquantifying colors in an imageとしたいと思います。 私は真珠の真珠光沢(真珠の母)を研究していますが、このシェル(例えば上のリンクの右の写真)の3色(赤、黄色、緑色)を定量化したいと思います。だから、イメージからの色抽出、定量および分析R

Iridescence of nacre

、私はいくつかのパッケージ(imagerImageMagickEBImageを...)テストだったが、私は本当に私を助けて何かを見つけることができません。

まあ、Rに、円で色分けしたいと思います。画素内のプリミティブの面積は、等価な表面積の円の面積として表すことができる。プリミティブは、類似の色の隣接画素の連続領域である。円の中心はアンカーピクセルになります。 [ - ² - (Ganchor - GI)² - (Banchor - BI)²(RI Ranchor)]

DeltaI =平方根: だから、私はそれがこれを行うには大丈夫だと思うの方程式があります

ここで、R、GおよびBは、0〜255の範囲のピクセルの色成分であり、アンカーはアンカーピクセルであり、iはアンカーピクセルの周りの同じ色である任意のピクセルです。

Alçiçek & Balaban 2012から)期待結果への画像リンクがあります:

Shrimp resulting equivalent circles

だから私の(ブート可能で働いていた)のコードがありますが、私は実際に継続するか見当がつかない。..かもしれませパッケージを作成しようとしていますか?

library(png) 
nacre <- readPNG("test.png") 
nacre 

dim(nacre) 

# show the full RGB image 
grid.raster(nacre) 

# show the 3 channels in separate images 
nacre.R = nacre 
nacre.G = nacre 
nacre.B = nacre 

# zero out the non-contributing channels for each image copy 
nacre.R[,,2:3] = 0 
nacre.G[,,1]=0 
nacre.G[,,3]=0 
nacre.B[,,1:2]=0 

# build the image grid 
img1 = rasterGrob(nacre.R) 
img2 = rasterGrob(nacre.G) 
img3 = rasterGrob(nacre.B) 
grid.arrange(img1, img2, img3, nrow=1) 
# Now let’s segment this image. First, we need to reshape the array into a data frame with one row for each pixel and three columns for the RGB channels: 


# reshape image into a data frame 
df = data.frame(
red = matrix(nacre[,,1], ncol=1), 
green = matrix(nacre[,,2], ncol=1), 
blue = matrix(nacre[,,3], ncol=1) 
) 


### compute the k-means clustering 
K = kmeans(df,4) 
df$label = K$cluster 

### Replace the color of each pixel in the image with the mean 
### R,G, and B values of the cluster in which the pixel resides: 

# get the coloring 
colors = data.frame(
    label = 1:nrow(K$centers), 
    R = K$centers[,"red"], 
    G = K$centers[,"green"], 
    B = K$centers[,"blue"] 
) 

# merge color codes on to df 
df$order = 1:nrow(df) 
df = merge(df, colors) 
df = df[order(df$order),] 
df$order = NULL 

# get mean color channel values for each row of the df. 
R = matrix(df$R, nrow=dim(nacre)[1]) 
G = matrix(df$G, nrow=dim(nacre)[1]) 
B = matrix(df$B, nrow=dim(nacre)[1]) 

# reconstitute the segmented image in the same shape as the input image 
nacre.segmented = array(dim=dim(nacre)) 
nacre.segmented[,,1] = R 
nacre.segmented[,,2] = G 
nacre.segmented[,,3] = B 

# View the result 
grid.raster(nacre.segmented) 

誰かがトラックや考えを持っていますか?任意の助け 感謝..

+0

「エビの結果の等価円」の正確な引用/記事を提供できますか?私は "Alçiçek&Balaban 2012"の紙を調べました。その写真はそこにありません! – Daniel

+0

@ダニエル、記事への良いリンクがあります(残念ながら、2つの投稿と10の評判を得る前に、私は編集上のURLリンクを投稿できません...そして、私はそれがなぜ他の人に見えないのか理解しています...) http://s3.amazonaws.com/academia.edu.documents/41113722/tiger_prawn.pdf?AWSAccessKeyId=AKIAIWOWYYGZ2Y53UL3A&Expires=1486502777&Signature=ZcX1eV8nqS1%2BYRSgvJZyAURvCwo%3D&response-content-disposition=inline%3B%20filename%3DVisual_Attributes_of_Hot_Smoked_King_Sal。 pdf –

+0

OK、ありがとう、あなたのリファレンスを更新しました! – Daniel

答えて

0

は、まあ、私は私の質問に答えるために、他の方法を見つけるしました:

(実際のコードスクリプトがより1000行程度であるので、私は後でGitHubのリンクを作成する、とのために今だけの要約:)

  • 私はimagerパッケージからload.imageと私の画像をアップロードしています。
  • 私はこのコードをRGBチャネルを抽出:

    # Assign RGB channels to data frame 
    nacreRGB <- data.frame(
    x = rep(1:nacreDm[2], each = nacreDm[1]), 
    y = rep(nacreDm[1]:1, nacreDm[2]), 
    R = as.vector(nacre[,,1]), 
    G = as.vector(nacre[,,2]), 
    B = as.vector(nacre[,,3]) 
    ) 
    # head(nacreRGB) 
    
    # Assign RGB channels to data frame without pixel coordinates 
    nacreRGB2 <- data.frame(
    R = as.vector(nacre[,,1]), 
    G = as.vector(nacre[,,2]), 
    B = as.vector(nacre[,,3]) 
    
  • IはrgbSVG2rgbCSS fonctionとHEXコードにこれを変換した後。

  • これを私がRGB0と呼んでいる行列に入れて、ヒストグラムを作成し、ピクセルの周波数でさまざまな色を表示します。
  • 私は、これらの色の分布を示すために、PCAを実行した後:

    require("ggplot2") 
    RGB0 <- as.data.frame(RGB0) 
    
    # perform PCA on the nacre data and add the uv coordinates to the 
    dataframe 
    PCA = prcomp(RGB0[,c("R","G","B")], center=TRUE, scale=TRUE) 
    RGB0$u = PCA$x[,1] 
    RGB0$v = PCA$x[,2] 
    
  • 私はggplot2でこのPCAを示しています。
  • これ以降、RGBコードをrgb2hsvでHSVコードに変換すると、色相、彩度(色相と白色)、値(色相と暗色)の値を持つことができるため、色に関する品質と量のデータを取得できます。
関連する問題