private Bitmap diffuse(VolumeData data, out long elapsedMilliSeconds) { Stopwatch sw = new Stopwatch(); sw.Start(); VolumeData convolved = VolumeData.Convolve1D(Data, Direction.Horizontal); sw.Stop(); elapsedMilliSeconds = sw.ElapsedMilliseconds; convolved.Scale255(); //OnChanged(new EventArgs()); OnChanged(66); #region conversion to bitmap /* Bitmap bmp = new Bitmap(convolved.Width, convolved.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int i = 0; i < convolved.Width; i++) for (int j = 0; j < convolved.Height; j++) try { int value = (int) convolved.Volume[i, j, 0]; bmp.SetPixel(i, j, Color.FromArgb(value, value, value)); } catch (Exception e) { int b; } */ #endregion Bitmap bmp = new Bitmap(1, 1); return bmp; }
public Bitmap run(out long elapsedMilliSeconds) { Data = new VolumeData(); var d = Directory.GetCurrentDirectory(); try { var path = "test.bmp"; //Data.Load( path ); Data.Load2(path); Data.ScaleMax(); } catch (IOException e) { } Bitmap diffused = this.diffuse(Data, out elapsedMilliSeconds); Data = null; return diffused; }
// Public Methods (7) //FIXME: replace operator+,-,* with delegate operator public VolumeData[] GetXYDifferences( VolumeData data ) { VolumeData XDifferences = new VolumeData( data.Height, data.Width, data.Depth ); VolumeData YDifferences = new VolumeData( data.Height, data.Width, data.Depth ); for ( int i = 0; i < data.Height; ++i ) for ( int j = 0; j < data.Width - 1; ++j ) for ( int k = 0; k < data.Depth; ++k ) XDifferences.Volume[i, j, k] = data.Volume[i, j, k] - data.Volume[i, j + 1, k]; for ( int i = 0; i < data.Height - 1; ++i ) for ( int j = 0; j < data.Width; ++j ) for ( int k = 0; k < data.Depth; ++k ) YDifferences.Volume[i, j, k] = data.Volume[i, j, k] - data.Volume[i + 1, j, k]; VolumeData[] set = new VolumeData[2]; set[0] = XDifferences; set[1] = YDifferences; return set; }
public static VolumeData Convolve1D( VolumeData data, Direction direction ) { VolumeData temp = new VolumeData( data.Width, data.Height, data.Depth ); temp.Height = data.Height; temp.Width = data.Width; temp.Depth = data.Depth; int kernelSize = 5; double[] kernel1D = { 0.0833333333333333, -0.666666666666667, 0, 0.666666666666667, -0.0833333333333333 }; short[] doubleIndexes = { -2, -1, 0, +1, +2 }; // check the odd size of kernel1D int _depth = data.Depth; int _width = data.Width; int _height = data.Height; switch ( direction ) { case Direction.Horizontal: unsafe { //for ( int i = kernelSize / 2 + 1; i < ( data.Width - ( kernelSize / 2 + 1 ) ) - 2; i++ ) for ( int k = 0; k < _depth; k++ ) for ( int i = 0; i < _width; i++ ) for ( int j = 0; j < _height; j++ ) { double sum = 0.0; for ( int m = 0; m < kernelSize; m++ ) { // try // { int indexes = i + doubleIndexes[m]; if ( indexes <= 0 ) indexes = Math.Abs( indexes ); if ( indexes >= _width ) indexes = _width - 1; //-( indexes - data.Width ); //double a = data.Volume[ i + m, j, k ]; double a = data[indexes, j, k]; double b = kernel1D[m]; sum += a*b; //temp[ i, j, k ] += data[ indexes, j, k ] * kernel1D[ m ]; //} //catch ( Exception e ) //{ // int a = 5; //} } // testing direct access temp[i, j, k] = sum; } } break; } return temp; }
public static VolumeData operator -( VolumeData data1, VolumeData data2 ) { VolumeData temp = new VolumeData( data1.Width, data1.Height, data1.Depth ); for ( int i = 0; i < data1.Width; ++i ) for ( int j = 0; j < data1.Height - 1; ++j ) for ( int k = 0; k < data1.Depth; ++k ) temp.Volume[i, j, k] = data1.Volume[i, j, k] - data2.Volume[i, j, k]; return temp; }