hi, i work on image comparison where focus ob basic geometric shape (rectangle, square, circle). i'm totally new to this language, i really need help...
i need to:
1) resize the image to 16x16 pixels
2)convert the image to binary (0's or 1's)
3) and compute it using algorithm.
i already search sample source code for conversion and image comparison. but still have the problem, and yet still does not know how to resize the read image to size 16x16 pixels.
if anybody can help me? i'm really appreciate,
Loading
Noor Aznimah Abdul AzizPosted Oct 2, 2009, 12:40 AM
TrinityPosted Sep 27, 2009, 5:12 PM
//This class implements System.Collection.Generics.Icomparer
public class ImageComparer : IComparer
{
private Image image1,image2;
//A private array that is used internaly
private Image[] ResizedImages;
//The constructor gets two images to compare them
public ImageComparer(Image image1, Image image2)
{
this.image1 = image1;
this.image2 = image2;
//The both images are stocked within the a public array
ResizedImages = new Image[2] { GetResizedImage(image1), GetResizedImage(image2) };
}
//This property is an array that contains the two compared images
public Image[] Images
{
get { return ResizedImages; }
}
//Is used to compare two images, you can ovveride it
protected Image GetResizedImage(Image image)
{
/*Provides a callback method for determining when the GetThumbnailImage
method should prematurely cancel execution.*/
Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
/*Resize the image*/
Image ResizedImage = image.GetThumbnailImage(16, 16, myCallback, IntPtr.Zero);
return ResizedImage;
}
/* This call back is for implementing logic that stops the resizing
* but in our case we won't implement this logic to simplfy the situation*/
private bool ThumbnailCallback()
{
return false;
}
//This interface method is used to compare the two images
#region IComparer
public int Compare(Image x, Image y)
{
int x1 = x.GetHashCode();
int y1 = y.GetHashCode();
return x1.CompareTo(y1);
}
#endregion
}
Thus you can compare two images using this code sample
//This code is used to show how to use this class
Image image1 = Image.FromFile(@"C:\trinity.jpg");
Image image2 = Image.FromFile(@"D:\trinity.jpg");
ImageComparer comparer = new ImageComparer(image1, image2);
int result = comparer.Compare(comparer.Images[0], comparer.Images[1]);
if (result == 1) label2.Text = "The both images are the same";
if (result == 0) label2.Text = "The both images are different";