Select based on object size?

Mar 30, 2020

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?

TOPICS
Actions and scripting, How to

Views

976

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Select based on object size?

Mar 30, 2020

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?

TOPICS
Actions and scripting, How to

Views

977

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 30, 2020 0
Mar 30, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 30, 2020 0
Mar 31, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 31, 2020 0
Apr 10, 2020

Copy link to clipboard

Copied

It can be done involving Math.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2020 0
Mar 31, 2020

Copy link to clipboard

Copied

Please post an example, to see if we can find a workaround for your problem... 😉

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 31, 2020 0
Apr 09, 2020

Copy link to clipboard

Copied

Thanks! Here's a low-resolution example of a manuscript page:

Untitled.jpg

I would like all instances of:

a.pngb.pngc.png

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.

  • One would be to slice the source page into small slices saved into individual files - small enough so that Object Select (or Subject Select?) works (as it seemed to when I tested a small cropped area of a couple of words a while back). Then invert selection and remove background. Then use a plugin that splits "islands" of pixels to layers (such as https://photoshopscripts.wordpress.com/2012/12/09/split-to-layers/, or https://scriptorator.readthedocs.io/en/latest/layerstoislands/index.html). Then save layers to files.
  • The other angle brings me back to my original notion of some script that utilizes selection size. I read that selection sizes (height and width) can indeed be accessed (With Navigator/Info palette open, Window>Info, use the Info tab, w/h shown near the bottom), and that there are scripts that can access these measurements. So I have still wondered why it wouldn't be possible to have a script that checked through all selections' sizes and only acted on the ones within a certain threshhold (eg, width of .5 cm to 1.5 cm) and ignored the rest. (In this case, I think I could just use color range to make selections, then rely on the script to winnow things down to what I need.)

 

All this said, I'm not particular to any method! Any help towards a quality, reusable solution would be wonderful.

 

All the best.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 09, 2020 0
Apr 10, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2020 1
Apr 19, 2020

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.)

18178_1_5.png

 

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.)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 19, 2020 0
Apr 19, 2020

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)

407_L.jpg

407_L.jpg

 

 

 

 

 

 

 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 19, 2020 1
Apr 21, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 21, 2020 1
Apr 21, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 21, 2020 1
Apr 21, 2020

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?

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 21, 2020 0
Apr 21, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 21, 2020 0
Jan 13, 2021

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)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 13, 2021 0
Jan 13, 2021

Copy link to clipboard

Copied

I'm not sure what you ask for. Use other number instead of 2.7?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 13, 2021 0
Jan 14, 2021

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.

vlazil_0-1610611054351.png

2.

vlazil_1-1610611320592.png

 

Nevermind, it is not a problem now.
I have another task, that seems like particulary the same, but different) Can i describe it here?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jan 14, 2021

Copy link to clipboard

Copied

Thank you a lot for your script. Sorry about my grammar and mistakes
:0)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jan 14, 2021

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.

 

bchNG130.pngbchNG140.pngbchNG150.pngbchNG160.pngbchNG160_mrks.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jan 14, 2021

Copy link to clipboard

Copied

Also I'm already use Split to layers script from this link:

https://photoshopscripts.wordpress.com/2012/12/09/split-to-layers/

It doing job well, but I can't understand how to focus layers with big islands and delete layers with small islands..

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jan 14, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jan 14, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2021 0
Jun 05, 2020

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...

page101vcrop.jpg

...if I hit the magic wand (threshold 60) on one of the lightest spots (and delete, to help you see the results), I get ...

Background copy.png

...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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 05, 2020 0