2014-02-06 3 views
1

가져온 컬러 그림을 그레이 스케일로 변환하려고합니다.Mathematica 그림 가져 오기 그레이 스케일 오류

SetDirectory[NotebookDirectory[]] 
testimage = Import["test.jpg"] 
matrixpic = getMatrix[testimage] 

matrixpic = getMatrix[testimage] 
greypic = 
    Graphics[ 
    Raster[ 
     matrixpic, {{0, 0}, {sizeX[matrixpic], sizeY[matrixpic]}}, {0, 
     255}, ColorFunction -> (GrayLevel[#[[1]]*0.3 + #[[2]]*0.5 + #[[ 
     3]]*0.2] &) 
    ], 
    ImageSize -> {sizeX[matrixpic], sizeY[matrixpic]}, 
    AspectRation -> Automatic 
] 

Show[greypic] 
+0

'ColorConvert [testimage, "Grayscale"]'의 문제점은 무엇입니까? –

+0

볼 수있는 값을 지정 하시겠습니까? –

답변

1

이 작동하고 있습니다 : 여기

내가 지금까지 시도했지만 티카 간단한 충돌이 코드를 실행 한 후, 어쩌면 당신은 내가 잘못 뭘하는지 인식 할 수없는 오류를 찾을 수있는 것입니다 더 많은 Mathematica 스타일 코드.

img = Import["ExampleData/lena.tif"] 

enter image description here

ImageApply[{.3, .5, .2}.# &, img] 

enter image description here


:
SetDirectory[NotebookDirectory[]]; 
img = Import["55th-All-Japan-Kendo-Champ2007-4.jpg"]; 
colorXform[p_] := p[[1]]*0.3 + p[[2]]*0.5 + p[[3]]*0.2; 
newImg = Image[Map[colorXform, ImageData[img], {2}]]; 
Show[newImg] 
2

나는이 변환을 할 수있는 가장 좋은 방법은 ImageApplyDot을 사용하는 것입니다 생각

는 전용 티카 StackExchange 사이트에 당신의 미래 질문을하시기 바랍니다 :

enter image description here

1

코드는 매스 매 티카 8.0.4 에서 오류없이

img = Import["ExampleData/lena.tif"]; 
matrixpic = ImageData[img, DataReversed -> True]; 
Graphics[Raster[matrixpic, 
    ColorFunction -> (GrayLevel[{.3, .5, .2}.#] &)]] 

이 작동을 단순화 할 수있다.