2017-02-07 21 views
1

quantifying colors in an image 싶습니다. 진주의 무지개 (진주의 어머니)에 대해 작업하고 있는데,이 껍질에 3 가지 색상 (빨강, 노랑, 초록색)을 정량화하려고합니다 (예 : 위 링크의 오른쪽 그림).색상 추출, 정량 및 분석에서 이미지에서 R

Iridescence of nacre

그래서, 테스트를 일부 패키지 (imager, ImageMagick, EBImage을 ...)했다,하지만 난 정말 나를 도와 뭔가를 찾을 수 없습니다.

음, R에 원으로 표시하고 싶습니다. 픽셀 내의 프리미티브의 면적은 등가 표면적 원의 면적으로 표현 될 수있다. 프리미티브는 유사한 색상의 인접 픽셀의 연속 영역입니다. 원의 중심은 앵커 픽셀이 될 수 있습니다. [- ² - (Ganchor - 승기) ² - (Banchor - BI) ² (리 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

@Daniel, 기사에 대한 좋은 링크가 있습니다. (불행히도, 나는 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]) 
    
  • 내가 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 코드로 변환하면 채도 (색조가 흰색 임)와 값 (색조가 어두움)에 대한 색조 값을 가질 수 있으므로 색에 대한 품질 및 수량 데이터를 얻을 수 있습니다 .