Copy link to clipboard
Copied
Hi. I want to select the writing on very old manuscripts. There are many pages, and I would like to automate all I can. I can use magic wand or color range to select the writing. But there is a lot of grainyness, tiny ink blots, and/or other defects that have come with age that also get selected.
Is there some way to include object size a parameter for selection? For example, the letters, like what I'm typing right now, are all within a very limited size threshhold. I was wondering if there might be a way to only select objects on such a basis. (I especially have a script in mind, fwiw.)
Or is there perhaps a better way to accomplish what I'm seeking to do altogether?
Copy link to clipboard
Copied
They aren't objects, just pixels and there is no built-in logic in PS that differentiates this beyond the parameters provided. Adding a specific surface area constraint would be quite convoluted, anyway, and taking care of special cases like commas, dots and similar is another exercise. You're also wrong about scripts - they have no magic beyond parametrically controlling existing functions. What you want simply doesn't exist in PS and thus couldn't be manipulated using scripts or actions. one would have to write a whole custom plug-in. That being the case, it's back to good old duplicating layers and processing them with adjustments to increase contrast and such and base the selections on that rather than the original sources.
Mylenium
Copy link to clipboard
Copied
Thank for taking time to respond, and for your explanation.
By "object," I just had in mind the lingo of Photoshop's Object Selection tool from the Magic Wand group. Or even "subject" in the sense of the Select Subject tool. But yes, it's all pixels.
One reason I had this in mind is because I tried to use these tools. The results are not good. But if I focus in and select a rectangle with just a word or two enclosed, then use the Object Selection tool, it grabs the letters as desired. What I'd like is for this to happen for whole pages, of course.
(Another clarification, just in case: I'm trying to get at the letters themselves; the text itself - not even the words - need to be intact. I'm not sure if that makes a difference or not.)
There is no punctuation in the document I have in mind (a medieval Latin manuscript), so that wouldn't be an issue. And since I'm aiming for the letters, smaller things getting left out would be okay anyways. Again, my hope is for a way to leave out things smaller than letters in general.
What I hear you saying is that there is no way to use size per se to dictate what does or what doesn't get selected. Thank you for clarifying that. If you think of any other angle, or any exception to this, I'd greatly appreciate knowing.
(For what it's worth, my relatively uneducated guess was that somewhere, somehow in the Subject Select tool's Sensei algorithm, size has to matter. (Kind-of like, "Hey, the full image is not a subject. It has to be smaller than that." And, "Hey, those little grains, regardless of color and contour, can't be subjects. You have to find something bigger." (This is closer to my simplistic way of thinking.)) And maybe this would be in the Object Selection tool's logic, too. (Idk.) Anyways, if this very loose concept had any resemblance of truth, then my hope was to likewise be able to instruct Photoshop to make size matter when making or working with (eg, subtracting from or adding to) a given selection.)
Thanks.
Copy link to clipboard
Copied
It can be done involving Math.
Copy link to clipboard
Copied
Please post an example, to see if we can find a workaround for your problem... 😉
Copy link to clipboard
Copied
Thanks! Here's a low-resolution example of a manuscript page:
I would like all instances of:
etc. These are rush jobs. But I'd like them a pixel or two outside the perimeters. And each saved as an image file. (And fwiw, there are many pages to this manuscript.)
I would really appreciate anyone's suggestions toward a solution. So far, only a couple of angles have come to me, but they are incomplete.
All this said, I'm not particular to any method! Any help towards a quality, reusable solution would be wonderful.
All the best.
Copy link to clipboard
Copied
I did something like it, so anyone willing can play with to adjust it to your needs:
How to remove small black dots from text page - selecting pixel radius via script
Copy link to clipboard
Copied
The script at that link is so helpful! Thank you very much.
I indeed aspire to play with it, as you put it. 🙂
I tried the script and was impressed, and I am very hopeful it will aid me greatly. I altered the "pat" function value to test the difference that made. I also tried your original code as well as the alteration you made later in the thread.
Since I'm a beginner, and since my goal is a little different than the person that needed that script, I really could use some assistance in understanding some things from the code. (Here's another example image, fwiw.)
So, the goal is to separate each letter (and ultimately to save each one to a file).
1. For one thing, I'm trying to figure out how to apply your code without any alterations at all to the letters themselves - no loss of color or resolution, no filling gaps, etc. (You mentioned some fill-in and some minor thinning and increase in contrast going on in the existing script.)
2. Would you mind explaining, if possible, exactly which part of the code uses size (pixel radius) to differentiate between small dots and letters?
3. When I run the script and then hit Ctrl+Z backwards through the steps, at one step I see small blue squares. Would you mind just explaining what those are? (My guess is they have to do with the measurements. But I searched, couldn't find anything online, and don't want to do too much guessing.)
Copy link to clipboard
Copied
1. increase / decrease some values in the script to see the effect. Some little changes may help
2. try that experincing with the script, 3. I'm not sure, but blue squares may be path(Items)
Maybe I have something wrong set in CC 2020, but it didn't work there (white layer as result).
Then I tried in CS6 and all was okey. You can try with other layer I'm providing.
It's not original that was put to dropbox in that thread, but result will be same:
(Just in case you can't get it, I post also how the result looks like on my side)
Copy link to clipboard
Copied
Once again, thank you so much, Kukurykus.
I understand how to change path precision ("pat" in the script), because that has a specific number ("2.7"). I'm having a really tough time figuring out how to increase/decrease values when those are written into formulas. For example, color range:
function cR2(v1, v2, v3, v4) {// UNSAMPLED COLOR RANGE: 'COLOR RANGE'
eval("(dsc1 = new ActionDescriptor())" + (v1 == 'skinTone' ? ".putInteger(sTT('fuzziness'), v4)" : ""))
dsc1.putEnumerated(sTT(C = (c = 'color') + 's'), sTT(C), sTT(v1))
for(i = 0; i < (arr = ['invert', 'UseFacesKey']).length; i++) dsc1.putBoolean(sTT(arr), eval('v' + (i + 2)) || false)
dsc1.putInteger(sTT(c + 'Model'), 0), executeAction(sTT(c + 'Range'), dsc1, DialogModes.NO)
// v1: 'radius', 'cyans', 'yellows', 'graininess', 'blues', 'magenta'
// 'highlights', 'midtones', 'shadows', 'skinTone', 'outOfGamut'
// v2: boolean; v3: boolean, v4: number (0 - 200)
How could I make the color range slightly broader? (If possible, it would be great not just to broaden it this once, but to understand how to do so myself, for future reference.)
Likewise, back to my initial question about object size, where in the script is size taken into account? I see ".length" twice. But if that's where it is, then like color range, I can't figure out how to adjust anything in order to include or exclude certain measurements. I would really love some guidance regarding that!
Sincere thanks to all pitching in and offering so much help - here and elsewhere in the forum.
Copy link to clipboard
Copied
Instead of above function use the same, but simpler (you can change values in):
sTT = stringIDToTypeID;
(dsc = new ActionDescriptor()).putEnumerated(sTT('colors'), sTT('colors'), sTT('shadows'))
dsc.putInteger(sTT('shadowsFuzziness'), 50), dsc.putInteger(sTT('shadowsUpperLimit'), 150)
dsc.putInteger(sTT('colorModel'), 0), executeAction(sTT('colorRange'), dsc, DialogModes.NO)
But to be honest, that script was made for other goal. Yours is to make selections of letters you then change for path, the other script would make a loop over, to extract many subpaths, each for other letter, then make a dinstict layer from each.
Copy link to clipboard
Copied
That color range script is helpful. Great!
Yes, you're exactly right. My goal is definitely different from the other person's. I am looking for anything that will help me - even if partially. 🙂
Just to clarify, in the original script, are you saying that the part that impacts selection based on size is the path tolerance ("pat")? Or is it something else?
Copy link to clipboard
Copied
Greater tolerance in path probably increases smoothness, so the bigger value the less selection remains, I mean will be turned into path.
Copy link to clipboard
Copied
Hello. Can you please help me to understand, how to change path precision ("pat" in the script) with specific number ("2.7")?
:0)
Copy link to clipboard
Copied
I'm not sure what you ask for. Use other number instead of 2.7?
Copy link to clipboard
Copied
Sorry. I understood how it works. Doing same actions manually and it is OK.
Some times it brings Errors (PS 2020):
1.
2.
Nevermind, it is not a problem now.
I have another task, that seems like particulary the same, but different) Can i describe it here?
Copy link to clipboard
Copied
Lack of ']' is caused by syntax typo or something more tricky.
'Grow' can't happen due to no selection at the image.
Copy link to clipboard
Copied
Thank you a lot for your script. Sorry about my grammar and mistakes
:0)
Copy link to clipboard
Copied
I have sequence of images, that consist of some islands.
Images are consequent, but contour of islands differs from one to another with each next step.
Can I use batch processing or script with configured parameters to variate islands size (may be use parameter like contour length in pixels) which I want to delete, and wich I want to remain?
Thank you for your attention.
Copy link to clipboard
Copied
To get rid of inner islands you would need more complex script that makes paths from selections, then checks size of each to remove smaller ones, alternatively checks paths points coordinates to compare with others. It all needs more scripting calculations than making the task by only Ps tools.
Copy link to clipboard
Copied
Also I'm already use Split to layers script from this link:
It doing job well, but I can't understand how to focus layers with big islands and delete layers with small islands..
Copy link to clipboard
Copied
Hi. I'm coming back around to my initial question, because my efforts to implement a solution have failed thus far.
Restated: In Photoshop, can I make a selection more precise by taking size into consideration?
I know this may not be clear, so I hope this example will help: On an image like this...
...if I hit the magic wand (threshold 60) on one of the lightest spots (and delete, to help you see the results), I get ...
...tons of unwanted "islands" selected in addition to the letters. (The letters are what I want.) Some islands are bigger than the biggest letter; most are smaller. I would like a way to eliminate these islands based on a range of width and/or height in pixels (or at the very least, a range of total pixel area).
Some qualifiers and thoughts:
- I'm a novice.
- I'm seeking to repeat this on numerous similar images, so I am looking for solution that can be automated (in a script or recorded action).
- I have explored at least a few noise-cancelling, blurring-type operations and the like; I haven't found them sufficient.(And I'm very open to hearing more suggestions along these lines that would serve my purposes. Even then, I would still love to hear how use size as a parameter in selecting objects in Photoshop.)
- "Connected components" with adjustable size parameters (maximums and minimums) seems to be a "thing" in image processing. How do we do that in Photoshop?
- I know I'm very new and green to all this, so please bear with me... There appear to be many ways to make improve precision of selections based on color (brightness, contrast, RBG channels, etc). Is adding a threshold for pixel width as a parameter complicated? I am really asking, because I really don't know.
Thanks!