Dividing by equal area

Here everybody can post his problems with PhotoLine
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Dividing by equal area

Beitrag von cathodeRay »

OK, here's a new challenge. I'm doing some calculation on inclined hull sections (don't ask, but if you do, it's for a metacentric moment analysis). The idea is to divide the immersed part of a section into two equal halves by area. The old traditional way of doing this was to trace the outline of each section onto paper, cut out the section, and balance it on a knife edge, with the blade at 90 degrees to the inclined waterline. By all accounts it was very tedious and error prone, not to mention the risk of stabbing or cutting yourself. I figured there had to be an easier way.

Assuming pixel count is a proxy for area (and as we are actually trying to locate the centre of buoyancy, area is being used as a proxy for volume and so displacement), I divided the section in half on what looked like an equal area on each side (drew a vector line and then merged it with the section layer), and flood filled each half with a distinctive colour (1st image below). I then used the histogram to get counts of the relevant colours (I set the colours to be non-saturated pure red and green so they would be easy to spot on the histogram), and then compared the counts (2nd and 3rd images). Noting the difference, I then moved the vector layer in the right direction to make the two sides more equal, and redid the flood fill and pixels counts. And so on until the two sides were as close as I could get them in area.

section.jpg
158.jpg
192.jpg

Now this does work, sort of. It is not exact, because the change in pixel numbers happens in multiples of the length of the dividing line contained within the immersed section. Now, what I am wondering is whether there is a way to improve this manual iterative process. The first and to me most obvious improvement would be a live window or equivalent showing the number of pixels of any one given colour at any time. Thus if there were 10000 combined red and green pixels, then getting either the red or the green to 5000 would be the answer.

I wonder if any one has any idea how to set about getting that live single colour pixel count display?

Thanks in advance.

CathodeRay
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Dividing by equal area

Beitrag von Martin Huber »

I don't have a perfect solution, but one that might be a bit easier. I have attached a sample document:
- The background contains the full shape in red (the red and green parts of your example, but all red).
- Above that is the same shape, but green.
- The green layer gets a rectangular vector layer as layer mask. By moving the layer mask left or right more or less of the green shape is visible.
- At the top is a histogram adjustment layer.

If you turn on "View > Dialogs > Adjustment Layers", moving the clipping layer will modify the histogram of the adjustment layer.
But to move the clipping layer you will have to activate it which will hide the histogram :-(

You could circumvent that by recording actions that activate the clipping layer, move it to the left/right and switch back to the histogram layer.

Martin
Count.pld
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Re: Dividing by equal area

Beitrag von cathodeRay »

Martin - thanks as ever for your input.

We have had similar thoughts - I too wondered about using some sort of sliding shutter and you have managed to implement that but as you say when you select that layer to move the shutter, the histogram display panel for the adjustment layer disappears. I don't suppose there is a way to make it persistent, so long as no other adjustment panel is in play? The free floating histogram (Tools > Histogram Correction) of course grabs the focus, so that isn't a work around. I also noticed that when I resized the screen grabs for uploading the colours got blurred a bit, and you have restored the pure solid colours.

I also wondered about using actions, since this is a repetitive iterative process. Maybe have an action that does as you suggest, but have it do it several times over the likely area, one pixel at a time, with a pause to capture the pixel count at each iteration.

I also wonder if there is a way to automate selection of the right bit of the histogram or is it a case of having to mouse over it manually each time?

Many thanks again

cathodeRay
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Dividing by equal area

Beitrag von Martin Huber »

I had in mind to create two actions for both directions, one performing a small step and one a large one. You could assign a shortcut to each of these actions (something like "Alt+arrow left" for the large step and "Shift+Alt+arrow left" for the small step).

Then you could place the mouse cursor at the correct position in the histogram and use the shortcuts to modify the proportions. Sadly, PhotoLine doesn't show the precise numbers after using the shortcut. I will change that, but for the time being it doesn't work.

Martin
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

If you paint the areas with RBB 50%, 0%, 0% (instead of 100%, 0%, 0%) and RGB 0%, 60%, 0%, then the histogram panel will show two spikes side by side. One red in the middle of the histogram and one green just on the right. They are updated real time.
No need for the histogram adjustment layer ...

Don't know if it is accurate enough for your need.

Have a nice 2019

Philippe
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Re: Dividing by equal area

Beitrag von cathodeRay »

Martin - thanks for the update.

Philippe - that is pretty much what I was doing (using absolute 0-255 numbers, 158 and 192), to get the spikes conveniently in the middle of the histogram but not on top of each other, but the histograms, at least on my display, were not very readable visually (see images 2 and 3 in my first post) and I had to mouse over the spike to get a numerical readout eg 158/11238, being a pixel count of 11238 of the 158 spike. The problem is the action of mouseing over the histogram changes the focus so you can't be active on the histogram (so its giving live info) and be active on the layer to move the shutter left and right.

BW

cathodeRay
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

cathodeRay hat geschrieben: Di 22 Jan 2019 14:43 Philippe - that is pretty much what I was doing (using absolute 0-255 numbers, 158 and 192), to get the spikes conveniently in the middle of the histogram but not on top of each other, but the histograms, at least on my display, were not very readable visually (see images 2 and 3 in my first post) and I had to mouse over the spike to get a numerical readout eg 158/11238, being a pixel count of 11238 of the 158 spike. The problem is the action of mouseing over the histogram changes the focus so you can't be active on the histogram (so its giving live info) and be active on the layer to move the shutter left and right.
The histogram panel does not need to have the focus, it is updated real time.

See attached a screen shot of what my histogram panel shows. It is pretty readable.
Attached also a screen shot of the histogram correction layer.
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

Instead of RGB, if you use shades of gray like 123 and 133, you can read the value of the "Mean" in the histogram palette.
If my guess is correct, you should read a mean=128 when you have the same number of pixels in each shade of gray.

Philippe
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Re: Dividing by equal area

Beitrag von cathodeRay »

Philippe - I think you are onto something!

First, and probably most important, you are right, the histogram docker panel is live, whether it has the focus or not. That is very important - well done for spotting that. It means we can do two things at once: adjust the image and see live updates in the histogram.

I was trying various things with the histogram panel and found that undocking it and stretching it as tall as possible meant that I could see slightly better what was going on (before stretching, crop of stretched one below):

HG1.jpg
HG2.jpg

I then realised the reason the spikes are so small is because the vast majority of the image is black, and we don't see the huge black spike (it appears to be hidden behind the left hand side of the panel, at position 0), we only see the much smaller pro rata colour spikes. So I copied only the two halves of the immersed hull to another layer and bingo - much better spikes (I've also changed the red and green to two greys equidistant from mid grey as you suggested):

HG3.jpg

Now the stats are a bit interesting. The first one I think is the mean, and it doesn't make obvious sense. The mean should be between the two greys I used (112 and 142), but it is not. Perhaps the mean is also counting the transparent/black pixels, and that's pulling the mean down - no doubt Martin or one of the other PhotoLine internals experts will be able to enlighten us. The standard deviation is of course meaningless - this in NOT a normally distributed dataset. But the median, now that is interesting. Its currently at 142, ie the middle value of all the pixel values lined up in order is in the 142 (lighter) sector.

Now, I have not tested this yet, but I think there will be a transition point, where moving the line of change from one grey to the other will also cause the median to change from 142 to 112 and back again - and that is the mid point!
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

The mean value takes in account the background color of your drawing (transparent dots as 255 and black as 0) .
The background should be gray 128, so it does not change the target mean of 128 (average of the light and dark gray of the areas to be balanced)

So you can use the mean (the first value) as the indicator.

Phil
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Re: Dividing by equal area

Beitrag von cathodeRay »

Phil - yes, that seems to work. See the image below. 127.99 was the closest I could get - if I changed another 1 pixel band it went over 128 by more than 0.01, to 128.03, so 127.99 was the closest I could get to 128.00. I also noticed some subtle boundary colour changes which I couldn't get rid of (I used a hard edge brush to add the colour) but as each boundary gradient was similar I don't think it will have thrown things out very much if at all.

Also worth noting that 50% grey is 128 (rather than 127) in PL (colour palate >select 50% grey using & then switch to 0-255), presumably because 127.5 is rounded up rather than down.

Mid point.jpg

Thanks very much for all your input and help, yet another PhotoLine achievement!

Best wishes

cathodeRay
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

To improve the sensitivity of the process, increase the difference between light and dark gray, like 90%gray and 10% gray.
Also, try to minimize the surface of the background so that its spike in the histogram is small.

Good luck.

I had a lot of fun taking this "challenge" with you.

Best regards from Belgium.

Philippe
cathodeRay
Mitglied
Beiträge: 151
Registriert: So 15 Nov 2015 12:37

Re: Dividing by equal area

Beitrag von cathodeRay »

All good suggestions, thanks.

Yes, its been great fun working this out, and great that we have got a straightforward working solution.

And thanks too to Martin for his contributions (and if at some point in the future the histogram could have live pixel count number as well as spike updates as well that would be great too!).

Very best wishes

cathodeRay
PhilM
Mitglied
Beiträge: 171
Registriert: Do 28 Mai 2015 18:00
Wohnort: Belgium

Re: Dividing by equal area

Beitrag von PhilM »

Martin,

Could you explain the calculation of the Mean, Std deviation and Median at the bottom of the histogram panel ?

Thanks.

Philippe
Martin Huber
Entwickler
Entwickler
Beiträge: 4159
Registriert: Di 19 Nov 2002 15:49

Re: Dividing by equal area

Beitrag von Martin Huber »

PhilM hat geschrieben: Do 24 Jan 2019 16:53Could you explain the calculation of the Mean, Std deviation and Median at the bottom of the histogram panel ?
Mean: sum of all pixel values / number of pixels
Std deviation: square root of ((sum of squares of all pixel values / number of pixels) - square of mean)
Median: if all pixel values are sorted ascending, the median is the pixel value in the middle of the resulting list

Martin