-1

I have multiple labels produced at multiple folders by diffrent softwares. the sizes of labels are same but their transparency labels varies.Ideally they are same, but when i compare using my internal application, it throws me error saying they mismatch.

I know similar questions asked, but they are not exactly matching the questions i have. I need to implement related algorithm using c#.

I am exploring few API AForge.Net, ImageMagick.

Till now i have compared bytes

filename1 = Path.Combine(directory.ToString(), new1[i].ToString());
filename2 = Path.Combine(directory1.ToString(), new2[i].ToString());

using (Bitmap bm1 = new Bitmap(filename1))
{
    using (Bitmap bm2 = new Bitmap(filename2))
    {
        // Make a difference image.
        int wid = Math.Min(bm1.Width, bm2.Width);
        int hgt = Math.Min(bm1.Height, bm2.Height);
        Bitmap bm3 = new Bitmap(wid, hgt);

        // Create the difference image.
        bool are_identical = true;
        Color eq_color = Color.White;
        Color ne_color = Color.Red;
        for (int x = 0; x < wid; x++)
        {
            for (int y = 0; y < hgt; y++)
            {
                //if (bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)))
                if (bm1.GetPixel(x, y) != (bm2.GetPixel(x, y)))
                {
                    //bm3.SetPixel(x, y, eq_color);
                    bm3.SetPixel(x, y, ne_color);
                    are_identical = false;

                }
                else
                {
                    //bm3.SetPixel(x, y, ne_color);
                    //are_identical = false;

                }
            }
            //I kept the code here before
        }
        if (!are_identical)
        {
            bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages" + new1[i]);
        }
        // Display the result.
        //picResult.Image = bm3;
        //bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages\" + new1[i]);
        this.Cursor = Cursors.Default;
        if ((bm1.Width != bm2.Width) || (bm1.Height != bm2.Height)) are_identical = false;
        if (are_identical)
        {
            //richTextBox1.Text = string.Format("Images are identical", "\r\n");
            sb.AppendLine("Image Name=" + new1[i] + " are identical at both folder");
        }
        else
        {
            //richTextBox1.Text = string.Format("Images are NOT MATCHING", "\r\n");
            sb.AppendLine("Image Name=" + new1[i] + " are Not Matching at both folder");
        }

        //sb.AppendLine(f1.Name + ": " + (equal ? "Images are equal" : "Images are NOT equal"));

    }
}
result.Add(sb.ToString());
gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • It seems you have a problem with your code. However, we can't help unless we have [code or information that can reproduce the problem](http://stackoverflow.com/help/mcve). Otherwise, we are just blindly guessing. – gunr2171 Jun 26 '15 at 13:05
  • Please provide some code of what you already did and your code that fails. It sounds to me like you just have to ignore the alpha channel, but that is just a first idea. – Nitram Jun 26 '15 at 13:05
  • Why negative? my code for emgucv Image bitmap = new Image(@"D:\red3.bmp"); Image bitmap1 = new Image(@"D:\red3.bmp"); Hsv lowerLimit = new Hsv(0, 0, 200); Hsv upperLimit = new Hsv(5, 255, 255); var imageHSVDest = bitmap.InRange(lowerLimit, upperLimit); CvInvoke.cvShowImage("imageHSVDest", imageHSVDest); bitmap.AbsDiff(bitmap1); – Sudhir pradhan Jun 26 '15 at 13:36

1 Answers1

0

I am not sure from your question if you do, or do not, want to use ImageMagick. If you do, you can disable the alpha/transparency channel with +matte or -alpha off.

So, if I create two red images, one with a radial gradient for transparency like this:

convert -size 500x500 xc:red \( radial-gradient:black-gray90 -sigmoidal-contrast 10,50% \) -compose copy-opacity -composite radial.png

enter image description here

and one with a straight gradient for transparency like this:

convert -size 500x500 xc:blue \( gradient:white-gray40 \) -compose copy-opacity -composite straight.png

enter image description here

I can then compare them using ImageMagick but ignoring the difference in transparency like this:

convert radial.png straight.png +matte -metric AE -compare format "Count of differing pixels:%[distortion]" info:
Count of differing pixels:0

That command says... load radial.png and straight.png into the image stack and remove the transparency from both, then count and report the total number of differing pixels - which is zero as the transparency has been removed.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Sorry for late reply, Why i am still facing issues. I have images of same name at diffrent folders, and i need to compare them. They are black and white images. (To be specific as shown in this link e.g. http://info.pcforms.com/DIY-Printing-blog/bid/26211/Why-can-t-I-tape-over-the-barcode-on-my-USPS-shipping-label ) due to build issues, though images containts are same but some time spacing and font sizes varies between two images. My customer is not happy with result (showing diffrent), as on naked eyes they looks all same. This problem i wanted to solve here. I tried OCR, but shows diff. – Sudhir pradhan Jul 14 '15 at 13:08