Unsupported Pixel Format of source or template image. AForge Imaging
10,262
Try ExhaustiveTemplateMatching
:
The class implements exhaustive template matching algorithm, which performs complete scan of source image, comparing each pixel with corresponding pixel of template.
The class processes only grayscale 8 bpp and color 24 bpp images.
So, those are the image formats you must use.
As requested, to convert to a specific pixel format, you can do this:
public static Bitmap ConvertToFormat(this Image image, PixelFormat format)
{
Bitmap copy = new Bitmap(image.Width, image.Height, format);
using (Graphics gr = Graphics.FromImage(copy))
{
gr.DrawImage(image, new Rectangle(0, 0, copy.Width, copy.Height));
}
return copy;
}
The one you would use is System.Drawing.Imaging.PixelFormat.Format24bppRgb
.
Related videos on Youtube
Author by
Charlie
Updated on June 26, 2022Comments
-
Charlie almost 2 years
I am getting the following Exception at
ProcessImage(bitmap1, bitmap2)
;Unsupported Pixel Format of source or template image
and this is my code:
public static double FindComparisonRatioBetweenImages( System.Drawing.Image one, System.Drawing.Image two) { Bitmap bitmap1 = new Bitmap(one); Bitmap bitmap2 = new Bitmap(two); ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0); TemplateMatch[] matchings = null; matchings = tm.ProcessImage(bitmap1, bitmap2); // Exception occurs here! return matchings[0].Similarity; }
I have also passed
managedImage
from the below code into the method, but it still gives error:UnmanagedImage unmanagedImageA = UnmanagedImage.FromManagedImage(bitmap1); Bitmap managedImageA = unmanagedImageA.ToManagedImage(); UnmanagedImage unmanagedImageB = UnmanagedImage.FromManagedImage(bitmap2); Bitmap managedImageB = unmanagedImageB.ToManagedImage();
- I have passed Images randomly from my computer, they all give exception.
- I have passed Blank Image edited in paint into the method,it still give exception.
- Also checked, jpeg, png, bmp formats, nothing work.
-
Charlie over 9 yearsCan i convert pixel Format of anyimage
-
dbc over 9 yearsSure, hold on a second.
-
Charlie over 9 yearstried to convert it from here stackoverflow.com/questions/2016406/… but it gives exception saying graphics can not be created from indexed pixel format
-
Charlie over 9 yearsI have used "PixelFormat.Format8bppIndexed"
-
dbc over 9 yearsWell, I'd go for
Format24bppRgb
sinceFormat8bppIndexed
only allows for up to 256 colors. -
RBK over 5 years@dbc I wanna use 16 bit grayscale image. Can I use it? I am trying to stitch image in Accord.net project having 16 bit images. I know it supports upto 8 bit. But my question is can I use it for 16 bits grayscale images???