Can Pixelmator tell me how many pixels are selected?

Chat about the original Pixelmator.
User avatar

2019-05-26 22:29:18

My photo is 36,152,320 pixels in total. I've carefully selected the sky section of the image using Quickmask. I need to know exactly how many pixels are now selected.

Can Pixelmator tell me this?

Thanks in advance for any help you can give.
User avatar

2019-05-27 18:34:43

Hi Eleventhvolume.
I can't think of a way of doing this directly. There are ways I can think of doing this indirectly, depending on if you need an exact or approximate count but all the techniques I can think of are a lot of work.
If you've not found a solution and if this is important enough to put the time in, reply and I'll guide as best as I can.
- Stef
User avatar

2019-05-27 18:50:04

Hello Stef, thanks for replying. It's for a project where I want to state the exact percentage of a series of photographs that contain sky which will be obscured by a building that's currently being built. I've carefully selected the sky in my first image using quick mask and the quick selection tool - which took quite a while in itself! Yes please if you can advise on a way to calculate the exact amount that would be great. Thanks again.
User avatar

2019-05-27 19:46:09

OK... there are two ways I can think of doing this. One involves some hand counting and maybe a spreadsheet/calculator, the second a bit of programming. Remember when I said this was a *lot* of work? :grin:
Both methods involve the same preparation.
You've selected a shape. Let's make an image layer with that information. I'd represent the information as black for 'not sky' and white for 'sky':
1. Create a new layer.
2. With the selection active and the colour set as white, use command-delete to fill. This will fill the selection onto the layer.
3. Assuming that this created a white shape the same as the selection. You can now deselect.
4. Create another layer and fill it completely black.
5. Merge the two layers. You now have a layer that is white where there is sky and black where there isn't.

You now have a decision to make. Assuming that you had a soft edge on your selection, you will have some grey pixels on this layer.
If you want a 50% grey pixel to count as 50% sky and 50% not sky then leave this as is.
If you only want something that is 100% sky to count as sky then you need to apply the threshold filter (Effects > Stylise > Threshold) at 100%.
If you want any pixel with any sky whatsoever to count as sky then I'd recommend inverting the layer, applying Threshold at 100% then inverting again.

Next... the count... which would you like?
Option 1: A bit of manual counting and a spreadsheet.
Option 2: Some programming.
User avatar

2019-05-27 21:12:38

Thanks Stef. I'd already done 1–5. On a 36mb image, I'm thinking there might be a lot of counting even for just the sky so I'll go for option 2, thanks.
User avatar

2019-05-27 21:31:08

That's a relief. I just checked out my method for option 1 (break it into squares with pixelate and total up greyscale values) but it didn't work (pixelate doesn't average a square, it just takes a single sample). :cry:
Option 2. I'd recommend something like Processing (https://processing.org) as it has bitmap support built into the language and it's relatively accessible (and free). You may have other preferences in which case go with those. If you do go down the Processing route, it has language choices. I tend to use Python as I find it easier for someone like me who writes a bit of code on average once a year.
Good luck. If you get stuck post back and I'll help if I can.
1. Export sky map image as .png (so you get no lossy compression).
2. Load into Processing using loadImage()
3. Convert the image to an array using loadPixels()
4. Loop through image calculating brightness of each pixel and summing up.
Processing python reference is here: https://py.processing.org/reference/
Hope this helps.
- Stef.
User avatar

2019-05-28 20:35:38

Thanks Stef, much appreciated. I have a developer friend who I can ask for help with if I get stuck.
User avatar

2019-05-28 21:49:55

Ho worries. Hope some of this helped. Best of luck!
- Stef.
User avatar

2021-07-23 14:11:54

Hi!

Although I wish there were a better way to measure pixels, there is an easier way than what's been suggested:

1. Using the rectangular selection tool, select the area you wish to measure.
2. Copy it to the clipboard (Cmd+C).
3. Create a new file (File/New or Cmd+N).

This will show the "New" dialog with the width and height in pixels.

Image

Cheers!

Mark