-5
C#을 사용하여 그레이 스케일 데이터를 컬러 이미지로 변환하고 싶습니다. 2D를 시도하고 1D 데이터를 변환하고 비트 맵을 표시하지만 컬러 이미지를 표시하려고합니다.C# 그레이 스케일 데이터를 컬러 이미지로 변환
C#을 사용하여 그레이 스케일 데이터를 컬러 이미지로 변환하고 싶습니다. 2D를 시도하고 1D 데이터를 변환하고 비트 맵을 표시하지만 컬러 이미지를 표시하려고합니다.C# 그레이 스케일 데이터를 컬러 이미지로 변환
.NET 프레임 워크의 그래픽 및 도면 기능이 내장되어있어 그레이 스케일 이미지 작업을 지원하지 않습니다.
회색 이미지를 잘못된 색상의 히트 맵으로 표시하는 데 동일한 작업을 수행했습니다.
/*
* -----------------------------------------------------------------------------------
* Step 3: Resize the gray image by using smoothing on it.
* This makes the image-data more smooth for further processing
* -----------------------------------------------------------------------------------
* */
var width = Convert.ToInt32(this.Params["Width"]);
var smoothWidth = Convert.ToInt32(width/150F);
grayShadeMatrix = grayShadeMatrix.Resize(width, Convert.ToInt32(width * (float)ySize/(float)xSize), Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
grayShadeMatrix = grayShadeMatrix.SmoothBlur(smoothWidth, smoothWidth);
#endregion
#region Step 4: Create HeatMap by applying gradient color
/*
* -----------------------------------------------------------------------------------
* Step 4: Create the heatmap by using the value of the every point as hue-angle for the color
* This way the color can be calculated very quickly. Also applies a log-function
* on the value, to make the lower values visible too
* -----------------------------------------------------------------------------------
* */
this.MaxHueValuePerValuePoint = MAX_HUE_VALUE/this.MaxValue;
this.MaxHueValuePreCompiled = Math.Log(MAX_HUE_VALUE, ScalaLogBase);
var grayShadeMatrixConverted = grayShadeMatrix.Convert<byte>(GetHueValue);
// Create the hsv image
var heatMapHsv = new Image<Hsv, byte>(grayShadeMatrixConverted.Width, grayShadeMatrixConverted.Height, new Hsv());
heatMapHsv = heatMapHsv.Max(255); // Set each color-channel to 255 by default (hue: 255, sat: 255, val: 255)
heatMapHsv[0] = grayShadeMatrixConverted; // Now set the hue channel to the calculated hue values
// Convert hsv image back to rgb, for correct display
var heatMap = new Image<Rgba, byte>(grayShadeMatrixConverted.Width, grayShadeMatrixConverted.Height, new Rgba());
CvInvoke.cvCvtColor(heatMapHsv.Ptr, heatMap.Ptr, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_HSV2RGB);
#endregion
함수 GetHueValue :
/// <summary>
/// Calculates the hue value by applying a logarithmic function to the values
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
private byte GetHueValue(ushort f)
{
f = Convert.ToUInt16(f < 1 ? 0 : f);
var hue = (double)MAX_HUE_VALUE/Math.Log((double)UInt16.MaxValue, ScalaLogBase) * Math.Log(f, ScalaLogBase);
hue = hue == Double.NegativeInfinity ? 0 : hue;
return Convert.ToByte(hue);
}
참고 : 그 varibale grayShadeMatrix 내 경우
나는이 내가 내 프로젝트에 사용되는 몇 가지 예제 코드가 Emgu.CV
라이브러리를 사용은 단 하나의 색상 채널 (회색 값)이있는 그레이 스케일 이미지입니다. 합니다 (greyimage 0의 값을인가했다 투명성)이 같은 이미지의
이 결과
그것은 이미 허용 가능한 답변을 갖는 인터 휴식 문제이다. 질문을 다시 말하고 지금까지 시도한 것을 보여주십시오. – Larry