Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, December 29, 2009 7:18:17 AM(UTC)
davidanderson

Groups: Registered
Posts: 7


Hi

take a look at this piece of code:
////////
RasterImage any = new RasterImage(Image.FromFile("any"));
RasterImage temp = any.Clone();
if (temp.Equals(any)) MessageBox.Show("They're equal");
////////

This comparison is always false.

How can I compare two RasterImage?

And if I want to compare a page with another image.
For example:
////////
RasterImage any = new RasterImage(Image.FromFile("any"));
RasterImage another = new RasterImage(Image.FromFile("another"));
RasterImage temp = any.Clone();
temp.AddPage(another);
temp.Page = 1;
if (temp.Equals(any)) MessageBox.Show("They're equal");
////////

Thanks a lot!
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, December 29, 2009 8:12:35 AM(UTC)
davidanderson

Groups: Registered
Posts: 7


By now I'm doign this way, but probably there's a better way =)
:

 public bool doImagesMatch(ref RasterImage img1, ref RasterImage img2)
        {
          
                //create instance or System.Drawing.ImageConverter to convert
                //each image to a byte array
                Bitmap bmp1 = Image.FromHbitmap(img1.ToHBitmap());
                Bitmap bmp2 = Image.FromHbitmap(img2.ToHBitmap());
                ImageConverter converter = new ImageConverter();
           
                //create 2 byte arrays, one for each image
                byte[] imgBytes1 = new byte[1];
                byte[] imgBytes2 = new byte[1];

                //convert images to byte array
                imgBytes1 = (byte[])converter.ConvertTo(bmp1, imgBytes2.GetType());
                imgBytes2 = (byte[])converter.ConvertTo(bmp2, imgBytes1.GetType());

                //now compute a hash for each image from the byte arrays
                SHA256Managed sha = new SHA256Managed();
                byte[] imgHash1 = sha.ComputeHash(imgBytes1);
                byte[] imgHash2 = sha.ComputeHash(imgBytes2);

                //now let's compare the hashes
                for (int i = 0; i < imgHash1.Length && i < imgHash2.Length; i++)
                {
                    //whoops, found a non-match, exit the loop
                    //with a false value
                    if (!(imgHash1[i] == imgHash2[i]))
                        return false;
                }
           
           
            //we made it this far so the images must match
            return true;
        }
 
#3 Posted : Tuesday, December 29, 2009 9:00:11 AM(UTC)

Walter  
Walter

Groups: Tech Support
Posts: 367

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)

Hello davidanderson,

Is there a specific reason why you're using the RasterImage contructor to create the image, as opposed to using the RasterCodecs.Load method? You would need something like this:

RasterCodecs.Startup();
RasterCodecs _codecs;
RasterImage any = _codecs.Load("any");

Depending on the file, you will have to include different Leadtools.Codecs.???.dlls with your application to load that specific file format.

Regarding comparing images, are you looking to see if one image is exactly like the other, or if one image is within the other? I would recommend looking at the CorrelationCommand class in Leadtools.ImageProcessing.Core.

AFAIK, the RasterImage object does not implement IComparable, so the Equals method has not been overridden. It would only use the default from System.Object, which would likely always return false in this case unless the memory addresses were exactly the same, i.e. any.Equals(any);
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#4 Posted : Tuesday, December 29, 2009 10:48:08 AM(UTC)
davidanderson

Groups: Registered
Posts: 7


No specific reason.

I wish to know if one image is exactly like the other.

This class would help me?

Thanks
 
#5 Posted : Wednesday, December 30, 2009 1:05:22 PM(UTC)

Walter  
Walter

Groups: Tech Support
Posts: 367

Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)

The CorrelationCommand is the only high-level method we have that could accomplish this. The only other option that you may want to try is using the RasterImage.GetRow or GetRowColumn methods, and comparing sections of pixels within the image to see if they're the same.

Figuring out if an image is exactly like another can get very complicated quickly. Even just having two images of different sizes can complicate such a comparison because all of the pixels will be offset from one to the other.
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.174 seconds.