public override void SegmentGray(Matrix<double> imageMatrix) { _checkAndAddToSegment = CheckAndAddToSegment_Gray; _imageMatrix = imageMatrix; _colorImage = null; _map = null; SegmentInternal(imageMatrix.RowCount, imageMatrix.ColumnCount); }
public override void SegmentDisparity(DisparityMap map) { _checkAndAddToSegment = CheckAndAddToSegment_Disparity; _map = map; _colorImage = null; _imageMatrix = null; SegmentInternal(map.RowCount, map.ColumnCount); }
public override void SegmentColor(ColorImage image) { _checkAndAddToSegment = CheckAndAddToSegment_Color; _colorImage = image; _imageMatrix = null; _map = null; SegmentInternal(image.RowCount, image.ColumnCount); }
public void FromColorImage(ColorImage cimage) { ImageMatrix = new DenseMatrix(cimage.RowCount, cimage.ColumnCount); int x, y; for(x = 0; x < ColumnCount; ++x) { for(y = 0; y < RowCount; ++y) { ImageMatrix[y, x] = (cimage[y, x, 0] + cimage[y, x, 1] + cimage[y, x, 2]) / 3; } } }
private void Build3DImage(object sender, RoutedEventArgs e) { if(_3dwindow == null) { _3dwindow = new Image3DWindow(); _3dwindow.Show(); } else { if(_3dwindow.IsVisible) _3dwindow.Close(); _3dwindow = new Image3DWindow(); _3dwindow.Show(); } _3dwindow.ResetPoints(); ColorImage image = null; if(_imageControl.ImageSource != null) { image = new ColorImage(); image.FromBitmapSource(_imageControl.ImageSource); } foreach(var point in Points3D) { SharpDX.Vector3 pos = new SharpDX.Vector3((float)point.Real.X, (float)point.Real.Y, (float)point.Real.Z); SharpDX.Color4 color = new SharpDX.Color4(1.0f); if(image != null) { if(!(point.Cam1Img.X < 0.0 || point.Cam1Img.X > image.ColumnCount || point.Cam1Img.Y < 0.0 || point.Cam1Img.Y > image.RowCount)) { color = new SharpDX.Color4( (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Red], (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Green], (float)image[(int)point.Cam1Img.Y, (int)point.Cam1Img.X, RGBChannel.Blue], 1.0f); } } _3dwindow.AddPointCube(pos, color); } }
public void FromColorImage(ColorImage cimage) { ImageMatrix = new Matrix<double>[3]; ImageMatrix[0] = new DenseMatrix(cimage.SizeY, cimage.SizeX); ImageMatrix[1] = new DenseMatrix(cimage.SizeY, cimage.SizeX); ImageMatrix[2] = new DenseMatrix(cimage.SizeY, cimage.SizeX); int x, y; double h, s, i; for(x = 0; x < SizeX; ++x) { for(y = 0; y < SizeY; ++y) { RGBToHSI(cimage[y, x, RGBChannel.Red], cimage[y, x, RGBChannel.Green], cimage[y, x, RGBChannel.Blue], out h, out s, out i); this[y, x, HSIChannel.Hue] = h; this[y, x, HSIChannel.Saturation] = s; this[y, x, HSIChannel.Intensity] = i; } } }
public ColorImageDebugView(ColorImage img) { _image = img; }
public IImage Clone() { ColorImage img = new ColorImage() { ImageMatrix = new Matrix<double>[3], }; img.ImageMatrix[0] = ImageMatrix[0].Clone(); img.ImageMatrix[1] = ImageMatrix[1].Clone(); img.ImageMatrix[2] = ImageMatrix[2].Clone(); return img; }
public void FromColorImage(ColorImage cimage) { ImageMatrix[0] = new DenseMatrix(cimage.RowCount, cimage.ColumnCount); ImageMatrix[1] = new DenseMatrix(cimage.RowCount, cimage.ColumnCount); ImageMatrix[2] = new DenseMatrix(cimage.RowCount, cimage.ColumnCount); int x, y; double h, s, i; for(x = 0; x < ColumnCount; ++x) { for(y = 0; y < RowCount; ++y) { RGBToHSI(cimage[y, x, RGBChannel.Red], cimage[y, x, RGBChannel.Green], cimage[y, x, RGBChannel.Blue], out h, out s, out i); this[y, x, HSIChannel.Hue] = h; this[y, x, HSIChannel.Saturation] = s; this[y, x, HSIChannel.Intensity] = i; } } }
/// <summary> /// Loads raw calibration images from children of supplied node /// </summary> private void LoadCalibrationImages(XmlNode imgsNode) { //<CalibrationImages_Raw> // <Image id="1" cam="left" path=""/> // <Image id="1" cam="right" path=""/> //</CalibrationImages_Raw> _rawCalibImages = new List<ColorImage>(); _calibImagesIndices = new List<ImageIndex>(); foreach(XmlNode imgNode in imgsNode.ChildNodes) { ImageIndex idx = ImageIndex.FromXml(imgNode); idx.ListIndex = _rawCalibImages.Count; string imgPath = imgNode.Attributes["path"].Value; BitmapImage bitmap = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute)); ColorImage image = new ColorImage(); image.FromBitmapSource(bitmap); _rawCalibImages.Add(image); _calibImagesIndices.Add(idx); } }
private void MatchImages(object sender, RoutedEventArgs e) { if(_camImageFirst.ImageSource == null || _camImageSec.ImageSource == null) { MessageBox.Show("Images must be set"); return; } if(_camImageFirst.ImageSource.PixelWidth != _camImageSec.ImageSource.PixelWidth || _camImageFirst.ImageSource.PixelHeight != _camImageSec.ImageSource.PixelHeight) { MessageBox.Show("Images must have same size"); return; } if(CalibrationData.Data.IsCamLeftCalibrated == false || CalibrationData.Data.IsCamRightCalibrated == false) { MessageBox.Show("Cameras must be calibrated"); return; } ColorImage imgLeft = new ColorImage(); imgLeft.FromBitmapSource(_camImageFirst.ImageSource); ColorImage imgRight = new ColorImage(); imgRight.FromBitmapSource(_camImageSec.ImageSource); _alg.ImageLeft = imgLeft; _alg.ImageRight = imgRight; _alg.StatusChanged += _alg_StatusChanged; _matcherWindow = new AlgorithmWindow(_alg); _matcherWindow.Show(); }
private void RectifyImages(object sender, RoutedEventArgs e) { if(_camImageFirst.ImageSource == null || _camImageSec.ImageSource == null) { MessageBox.Show("Images must be set"); return; } if(_camImageFirst.ImageSource.PixelWidth != _camImageSec.ImageSource.PixelWidth || _camImageFirst.ImageSource.PixelHeight != _camImageSec.ImageSource.PixelHeight) { MessageBox.Show("Images must have same size"); return; } if(CalibrationData.Data.IsCamLeftCalibrated == false || CalibrationData.Data.IsCamRightCalibrated == false) { MessageBox.Show("Cameras must be calibrated"); return; } ImageRectification_ZhangLoop rectifier = new ImageRectification_ZhangLoop(); RectificationTransformation rectTransformation = new RectificationTransformation(); rectTransformation.Rectifier = rectifier; ImageTransformer transformer = new ImageTransformer(); transformer.Transformation = rectTransformation; transformer.UsedInterpolationMethod = ImageTransformer.InterpolationMethod.Quadratic; rectifier.ImageHeight = _camImageFirst.ImageSource.PixelHeight; rectifier.ImageWidth = _camImageFirst.ImageSource.PixelWidth; rectifier.EpiCrossLeft = CalibrationData.Data.EpipoleCrossLeft; rectifier.EpiCrossRight = CalibrationData.Data.EpipoleCrossRight; rectifier.EpipoleLeft = CalibrationData.Data.EpipoleLeft; rectifier.EpipoleRight = CalibrationData.Data.EpipoleRight; rectifier.IsEpiLeftInInfinity = CalibrationData.Data.EpiLeftInInfinity; rectifier.IsEpiRightInInfinity = CalibrationData.Data.EpiRightInInfinity; rectifier.FundamentalMatrix = CalibrationData.Data.Fundamental; rectifier.ComputeRectificationMatrices(); ColorImage imgLeft = new ColorImage(); imgLeft.FromBitmapSource(_camImageFirst.ImageSource); ColorImage imgRight = new ColorImage(); imgRight.FromBitmapSource(_camImageSec.ImageSource); rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Left; ColorImage rectLeft = transformer.TransfromImageBackwards(imgLeft, true); rectTransformation.WhichImage = RectificationTransformation.ImageIndex.Right; ColorImage rectRight = transformer.TransfromImageBackwards(imgRight, true); _camImageFirst.ImageSource = rectLeft.ToBitmapSource(); _camImageSec.ImageSource = rectRight.ToBitmapSource(); }
private void _butSegment_Click(object sender, RoutedEventArgs e) { if(_imageControl.ImageSource != null) { ColorImage img = new ColorImage(); img.FromBitmapSource(_imageControl.ImageSource); var window = new ParametrizedProcessorsSelectionWindow(); window.AddProcessorFamily("Segmentation"); window.AddToFamily("Segmentation", new MeanShiftSegmentation()); window.ShowDialog(); if(window.Accepted) { ImageSegmentation segmentation = (ImageSegmentation)window.GetSelectedProcessor("Segmentation"); GrayScaleImage imgGray = new GrayScaleImage(); imgGray.FromColorImage(img); //segmentation.SegmentColor(img); segmentation.SegmentGray(imgGray.ImageMatrix); //var segments = segmentation.Segments_Color; var segments = segmentation.Segments; int[,] indices = segmentation.SegmentAssignments; ColorImage imgFinal = new ColorImage(); imgFinal.ImageMatrix[0] = new DenseMatrix(img.RowCount, img.ColumnCount); imgFinal.ImageMatrix[1] = new DenseMatrix(img.RowCount, img.ColumnCount); imgFinal.ImageMatrix[2] = new DenseMatrix(img.RowCount, img.ColumnCount); for(int r = 0; r < img.RowCount; ++r) { for(int c = 0; c < img.ColumnCount; ++c) { imgFinal[r, c, RGBChannel.Red] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value; imgFinal[r, c, RGBChannel.Green] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value; imgFinal[r, c, RGBChannel.Blue] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value; //imgFinal[r, c, RGBChannel.Red] = segments[indices[r, c]].Red; // imgFinal[r, c, RGBChannel.Green] = segments[indices[r, c]].Green; //imgFinal[r, c, RGBChannel.Blue] = segments[indices[r, c]].Blue; } } _imageControl.ImageSource = imgFinal.ToBitmapSource(); } } }
public abstract void SegmentColor(ColorImage image);