문제

How can I convert a colorful(RGB) jpeg image to gray scale?

The code I am working with only accepts the gray scale images but I want to feed colorful images as well.

rawimg=readJPEG("winter.jpeg")
rawimg=t(rawimg)
rawimg=rawimg[,ncol(rawimg):1]
image(rawimg,col = grey((0:12)/12))
도움이 되었습니까?

해결책

I am not sure if any R-specific functionality exists to convert a JPEG image into grayscale. However, writing this functionality yourself would not be difficult.

Assuming that the JPEG image uses the sRGB primaries (it almost certainly does, so don't worry too much about this), the most common conversion function to grayscale is given by the ITU-R reccomendation BT.709 Luma function:

Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'

You can use traditional R techniques to apply this to each spatial location in your image.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top