Replace all photos that are a placeholder
When the two systems sync, there MUST be an image or the program crashes so we put a nice placeholder image with the customer’s logo. Its a grey slab with the logo. With takeovers and mergers and time for a face lift, companies update their logo! Well now we are in a pickle, because the images is copied all over. Well, we made a quick macro, looked for the average greyscale of the image, hashed it and … VERY CONSISTENT results. No need to make a copy routine – just dump all these metrics to excel and add a column at the end with an xcopy command with the new one and your done! Simple.
We had to change all the placeholder images in the countertop industry. Two different systems are we synchronized – yes we build this software. It syncs between two different popular granite countertop managent software AND a very popular layout software. This layout software allows you to place REAL countertop hi-res images into templated kitchens and bathrooms in essence matching up veins of the rock without making any real cuts; no chances for mistakes because you haven’t done anything real. The management software allows inventory, process and other details about every slab at every stage of the slab’s life cycle. We also set these software’s up and maintain them.
Within about 1/2 hour the slabs are all renamed. You can re-run the software as a double check. This macro software is NOT fully built out with a nice interface which keeps the cost down. Scripts/Macros like these need to be run about every 3 years for every company – proving that you do NOT need to build fully polished tool.
Lets keep the cost and overhead down for all parties – a win-win.
On a nerdy note, since this is why I made most of these blog posts, do NOT use System.Drawing.Image – it crashes after 90,000 images repeatedly. You can set it to null, clear all sorts of this or that – then if you look up others who have these issues, sure enough DO NOT USE IT. System.Drawing.Bitmap worked well instead.
</pre>
public ImageAnalysisResult IsMostlyGrayscale(string imagePath)
{
using var bitmap = new Bitmap(imagePath);
int width = bitmap.Width;
int height = bitmap.Height;
int grayscalePixels = 0;
int totalPixels = width * height;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
Color c = bitmap.GetPixel(x, y);
int max = Math.Max(c.R, Math.Max(c.G, c.B));
int min = Math.Min(c.R, Math.Min(c.G, c.B));
int diff = max - min;
if (diff <= PixelThreshold)
{
grayscalePixels++;
}
}
}
double ratio = (double)grayscalePixels / totalPixels;
return new ImageAnalysisResult
{
grayscaleValue = ratio,
IsMostlyGrayscale = ratio >= GrayscaleRatioThreshold,
Width = width,
Height = height
};
}