LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Compare similar images to determine higher contrast
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Tuesday, February 26, 2013 12:35:25 AM(UTC)
Groups: Registered
Posts: 256
The concept of contrast of a particular image can have multiple meanings, but they usually revolve around the ability to distinguish objects in the image. However, if you have 2 similar images, like the same object photographed by 2 devices from the same angle, you can get a measure of which one has the "higher" contrast value.
In general, a higher contrast image will have a greater spread of the histogram curve, since this will mean the contents of the image have more differences in their intensities, which leads to greater ability to distinguish objects.
You can use StatisticsInformationCommand Class to get the properties of the histogram of the image and detect which one has higher contrast based on which image has a higher standard deviation.
For an example, see the following code which was tested using v18 of LEADTOOLS .NET classes (but other versions should work too):
=====================================
RasterImage img1 = codecs.Load(fileName1);
StatisticsInformationCommand cmd1 = new StatisticsInformationCommand(RasterColorChannel.Master, 0, 255);
RasterImage img2 = codecs.Load(fileName2);
StatisticsInformationCommand cmd2 = new StatisticsInformationCommand(RasterColorChannel.Master, 0, 255);
cmd1.Run(img1);
cmd2.Run(img2);
if (cmd1.StandardDeviation > cmd2.StandardDeviation)
{
MessageBox.Show(fileName1 + " likely has higher contrast");
}
else if (cmd1.StandardDeviation < cmd2.StandardDeviation)
MessageBox.Show(fileName2 + " likely has higher contrast");
else
MessageBox.Show("Standard deviation is equal");
=====================================
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Compare similar images to determine higher contrast
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.