private void toAdaptiveYCrCbEqualization(Mat img) { if (img.NumberOfChannels < 3) { MessageBoxResult result = MessageBox.Show("흑백 영상은 변환할 수 없습니다.", "경고"); return; } CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2YCrCb); var channels = CurrentMat.Split(); // 이미지 채널 분리 CvInvoke.CLAHE(channels[0], 2, new System.Drawing.Size(8, 8), channels[0]); CvInvoke.CLAHE(channels[1], 2, new System.Drawing.Size(8, 8), channels[1]); CvInvoke.CLAHE(channels[2], 2, new System.Drawing.Size(8, 8), channels[2]); VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); temp.Push(channels[1]); temp.Push(channels[2]); CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.YCrCb2Bgr); showImg(CurrentMat); }
private void toYCrCbHistogramEqulization(Mat img) { if (img.NumberOfChannels >= 3) { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2YCrCb); var channels = CurrentMat.Split(); // 이미지 채널 분리 CvInvoke.EqualizeHist(channels[0], channels[0]); // Y VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); temp.Push(channels[1]); temp.Push(channels[2]); CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.YCrCb2Bgr); } else { CvInvoke.EqualizeHist(img, CurrentMat); } showImg(CurrentMat); }
private void toSplitColor(Mat img, int selectColor) { switch (selectColor) { #region BGR 채널 보기 case 1: { var channels = img.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); // B temp.Push(empty); // G temp.Push(empty); // R CvInvoke.Merge(temp, CurrentMat); showImg(CurrentMat); break; } case 2: { var channels = img.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // B temp.Push(channels[0]); // G temp.Push(empty); // R CvInvoke.Merge(temp, CurrentMat); showImg(CurrentMat); break; } case 3: { var channels = img.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // B temp.Push(empty); // G temp.Push(channels[0]); // R CvInvoke.Merge(temp, CurrentMat); showImg(CurrentMat); break; } #endregion #region LUV 채널 보기 case 4: { break; } case 5: { break; } case 6: { break; } #endregion #region Lab 채널 보기 case 7: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Lab); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); // L temp.Push(empty); // a temp.Push(empty); // b CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Lab2Bgr); showImg(CurrentMat); break; } case 8: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Lab); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(191.25)); Mat empty2 = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty2.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // L temp.Push(channels[1]); // a temp.Push(empty2); // b CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Lab2Bgr); showImg(CurrentMat); break; } case 9: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Lab); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(191.25)); Mat empty2 = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty2.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // L temp.Push(empty2); // a temp.Push(channels[2]); // b CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Lab2Bgr); showImg(CurrentMat); break; } #endregion #region YCrCb 채널 보기 case 10: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2YCrCb); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); // Y temp.Push(empty); // Cr temp.Push(empty); // Cb CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.YCrCb2Bgr); showImg(CurrentMat); break; } case 11: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2YCrCb); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // Y temp.Push(channels[1]); // Cr temp.Push(empty); // Cb CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.YCrCb2Bgr); showImg(CurrentMat); break; } case 12: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2YCrCb); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(127.5)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // Y temp.Push(empty); // Cr temp.Push(channels[2]); // Cb CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.YCrCb2Bgr); showImg(CurrentMat); break; } #endregion #region HSV 채널 보기 case 13: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Hsv); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(255)); VectorOfMat temp = new VectorOfMat(); temp.Push(channels[0]); // H temp.Push(empty); // S temp.Push(empty); // V CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Hsv2Bgr); showImg(CurrentMat); break; } case 14: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Hsv); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(179)); Mat empty2 = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty2.SetTo(new MCvScalar(255)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // H temp.Push(channels[1]); // S temp.Push(empty2); // V CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Hsv2Bgr); showImg(CurrentMat); break; } case 15: { CvInvoke.CvtColor(img, CurrentMat, ColorConversion.Bgr2Hsv); var channels = CurrentMat.Split(); // 이미지 채널 분리 Mat empty = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty.SetTo(new MCvScalar(179)); Mat empty2 = new Mat(img.Rows, img.Cols, DepthType.Cv8U, 1); empty2.SetTo(new MCvScalar(0)); VectorOfMat temp = new VectorOfMat(); temp.Push(empty); // H temp.Push(empty2); // S temp.Push(channels[2]); // V CvInvoke.Merge(temp, CurrentMat); CvInvoke.CvtColor(CurrentMat, CurrentMat, ColorConversion.Hsv2Bgr); showImg(CurrentMat); break; } #endregion } }