public ProcessImage ( |
||
image | Source unmanaged image to process. | |
rect | Image's rectangle to process. | |
리턴 | void |
public void ProcessImage( UnmanagedImage image, Rectangle rect )
{
if ( image.PixelFormat != PixelFormat.Format8bppIndexed )
{
throw new UnsupportedImageFormatException( "Unsupported pixel format of the source image." );
}
// get source image size
int width = image.Width;
int height = image.Height;
int halfWidth = width / 2;
int halfHeight = height / 2;
// make sure the specified rectangle recides with the source image
rect.Intersect( new Rectangle( 0, 0, width, height ) );
int startX = -halfWidth + rect.Left;
int startY = -halfHeight + rect.Top;
int stopX = width - halfWidth - ( width - rect.Right );
int stopY = height - halfHeight - ( height - rect.Bottom );
int offset = image.Stride - rect.Width;
// calculate Hough map's width
int halfHoughWidth = (int) Math.Sqrt( halfWidth * halfWidth + halfHeight * halfHeight );
int houghWidth = halfHoughWidth * 2;
houghMap = new short[houghHeight, houghWidth];
// do the job
unsafe
{
byte* src = (byte*) image.ImageData.ToPointer( ) +
rect.Top * image.Stride + rect.Left;
// for each row
for ( int y = startY; y < stopY; y++ )
{
// for each pixel
for ( int x = startX; x < stopX; x++, src++ )
{
if ( *src != 0 )
{
// for each Theta value
for ( int theta = 0; theta < houghHeight; theta++ )
{
int radius = (int) Math.Round( cosMap[theta] * x - sinMap[theta] * y ) + halfHoughWidth;
if ( ( radius < 0 ) || ( radius >= houghWidth ) )
continue;
houghMap[theta, radius]++;
}
}
}
src += offset;
}
}
// find max value in Hough map
maxMapIntensity = 0;
for ( int i = 0; i < houghHeight; i++ )
{
for ( int j = 0; j < houghWidth; j++ )
{
if ( houghMap[i, j] > maxMapIntensity )
{
maxMapIntensity = houghMap[i, j];
}
}
}
CollectLines( );
}
HoughLineTransformation::ProcessImage ( |
|
HoughLineTransformation::ProcessImage ( |
|
HoughLineTransformation::ProcessImage ( |
|
HoughLineTransformation::ProcessImage ( |
|
HoughLineTransformation::ProcessImage ( |
//1. bright pixel / dark pixel //2.lowest gray level //3.highest gray level //4.number of peaks in the x direction. //5.number of peaks in the y direction. public static double[] ExtractFeatures(Bitmap bmp,int i) { //Apply GrayScale GrayscaleBT709 greyScaleFilter = new GrayscaleBT709(); Bitmap newBmp = greyScaleFilter.Apply((Bitmap)bmp.Clone()); //Count Blobs BlobCounter blobCounter = new BlobCounter(); blobCounter.BackgroundThreshold = Color.FromArgb(255, 150, 150, 150); blobCounter.ProcessImage(newBmp); int blobs = (blobCounter.ObjectsCount - 1) * 30; //Count Corner SusanCornersDetector scd = new SusanCornersDetector(); scd.DifferenceThreshold = 70; scd.GeometricalThreshold = 8; int corners = scd.ProcessImage((Bitmap)newBmp.Clone()).Count(); //Apply Edge Filter CannyEdgeDetector filter = new CannyEdgeDetector(); //newBmp = filter.Apply(newBmp); Histogram his = new HorizontalIntensityStatistics(newBmp).Gray; Histogram vis = new VerticalIntensityStatistics(newBmp).Gray; HoughLineTransformation lineTransform = new HoughLineTransformation(); // apply Hough line transofrm lineTransform.ProcessImage(filter.Apply(newBmp)); Bitmap houghLineImage = lineTransform.ToBitmap(); // get lines using relative intensity HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(1); int linesCount = lines.Count() * 30; double[] features = new double[13] { blobs, corners, his.Max, his.Min, his.Mean, his.Median, his.StdDev, vis.Max, vis.Min, vis.Mean, vis.Median, vis.StdDev,linesCount}; //double[] features = new double[3] { blobs, corners,lines}; newBmp.Save(String.Format("test{0}.bmp",i)); return features; }