Copy link to clipboard
Copied
I have 1000s of 24x24 px PNGs (always exactly 24x24) and I want to compare each (in bulk) against a larger 2400x2400px PNG - and output to a TXT file the status of whether the 24x24 px PNG is found within the larger 2400x2400 px PNG - e.g. an ideal output would be something as simple as...
image1.png,true
image2.png,false
image3.png,true
...
image1000.png,true
I'm looking for exact match - i.e. the 24x24 pixel area would also be a 24x24 pixel area in the larger image. If it helps to make the process more efficient - the larger 2400x2400 is a tiled combination of 10K similar (but not always the same) 24x24 pixel variants (100 of the smaller PNGs wide by 100 of the smaller PNGs tall) - so each smaller image.png need only be compared to 10K possible positions (e.g. 0,0 for upper left, then 25,0 for 2nd position, on top row, etc.).
Ideally - there's a way to allow for a minimal fuzz factor - e.g. in the 24x24, some of the "R" "G" or "B" values may be ever so slightly different. e.g.
a pixel in the smaller 24x24 may be RGB = 93.115.106
whereas in the original it's RBG = 92.115.107
Hoping to get some advise on how to proceed.
/////////////////////////////////////////////////////////
// Make sure to set your paths correctly !!!
var png2400 = new File("C:\\TEST\\2400x2400.png"); // main 2400x2400.png
var res_file = new File("C:\\TEST\\result.txt"); // result file
var png_folder = new Folder("C:\\TEST\\PNG"); // folder with 24x24 pngs
/////////////////////////////////////////////////////////
var images = new Array();
var doc = app.open(png2400);
var tmp = new File(Folder.temp.fsName + "\\" + "tmp.raw");
...
Copy link to clipboard
Copied
There may or may not be metadata that can be used to see if one images is used inside another from either copy/paste or place, perhaps one or more of these metadata entries exist.
<xmpMM:InstanceID>
<xmpMM:DocumentID>
<xmpMM:OriginalDocumentID>
Otherwise, you could compare an average of the 24x24 area, or perhaps the first row of 24 pixels etc.
How this would be automated, I don't know.
I'll get out the popcorn and keep an eye on this thread!
Copy link to clipboard
Copied
Thanks - no metadata in the 24x24s as they are patterns I've created with an algorithm - and I'm trying to see wehther they are a match to patterns in the larger 2400x2400. Can't compare just first row, as all pixels of the 24x24 need to match - lots of false positives if I just compare some of the pixels. Thanks for the eyes - let's see if anyone knows together.
Copy link to clipboard
Copied
If the patterns were copy/pasted or placed, then Photoshop may have recorded the source document metadata, unless this was removed. If the source file have no metadata but the composite does, then you only have half the info. It was a slim hope anyway. Good luck!
Copy link to clipboard
Copied
Without images I don't see it.
Copy link to clipboard
Copied
I may be misunderstanding, so please clarify:
You want to check a bunch of images (how many exactly?) against one of 10.000 possible matches in a larger image?
And the »matches« are not even exact, but can be off by one value in each channel?
Please post examples.
Because so far I am afraid that this task might be so time-intensive it might become pointless …
Copy link to clipboard
Copied
I found a process (using ImageMagick) to correct the pixel color value differences - so no longer need the "fuzzy" match.
But yes, I have ~12K PNGs - all 24x24. I want to check each to see if it's contained (without any distortions of size or pixel color) in the bigger 2400x2400 PNG. Someone on reddit has given some suggestions to use a python script - which may be beyond my ability - so still seeing if there's something that can be done via Photoshop.
Copy link to clipboard
Copied
We still wait for images 🙂
Copy link to clipboard
Copied
/////////////////////////////////////////////////////////
// Make sure to set your paths correctly !!!
var png2400 = new File("C:\\TEST\\2400x2400.png"); // main 2400x2400.png
var res_file = new File("C:\\TEST\\result.txt"); // result file
var png_folder = new Folder("C:\\TEST\\PNG"); // folder with 24x24 pngs
/////////////////////////////////////////////////////////
var images = new Array();
var doc = app.open(png2400);
var tmp = new File(Folder.temp.fsName + "\\" + "tmp.raw");
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("fileCreator"), "8BIM");
d1.putBoolean(stringIDToTypeID("channelsInterleaved"), true);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("rawFormat"), d1);
d.putPath(stringIDToTypeID("in"), tmp);
d.putBoolean(stringIDToTypeID("copy"), true);
d.putBoolean(stringIDToTypeID("alphaChannels"), false);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
doc.close(SaveOptions.DONOTSAVECHANGES);
tmp.open("r");
tmp.encoding = "BINARY";
for (var x = 0; x < 100; x++)
{
for (var y = 0; y < 100; y++)
{
images.push(get_img(tmp, x,y));
}
}
tmp.close();
tmp.remove();
function get_img(file, x, y)
{
var data = "";
y*=24;
for (var i = 0; i < 24; i++)
{
file.seek(x*3*24 + 3*2400*(y+i) , 0);
data += file.read(3*24);
}
return data;
}
var files = png_folder.getFiles("*.png");
var len = images.length;
res_file.open("w");
res_file.close();
app.doForcedProgress("Process", "f()");
res_file.close();
alert("done");
function f()
{
for (var i = 0; i < files.length; i++)
{
var doc = app.open(files[i]);
if (!app.updateProgress(i, files.length)) executeAction(stringIDToTypeID("stop"), undefined, DialogModes.NO);
app.changeProgressText("Processing: " + (i+1) + " of " + files.length);
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("fileCreator"), "8BIM");
d1.putBoolean(stringIDToTypeID("channelsInterleaved"), true);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("rawFormat"), d1);
d.putPath(stringIDToTypeID("in"), tmp);
d.putBoolean(stringIDToTypeID("copy"), true);
d.putBoolean(stringIDToTypeID("alphaChannels"), false);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
tmp.open("r");
tmp.encoding = "BINARY";
var img = tmp.read();
tmp.close();
var found = false;
for (var n = 0; n < len; n++)
{
if (images[n] == undefined) continue;
if (images[n] == img)
{
found = true;
//delete images[n]; // uncomment if 24x24 png are unique (there are definitely no duplicate files)
break;
}
}
res_file.open("a");
res_file.writeln(doc.name + ", " + found);
res_file.close();
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}