3
$\begingroup$

I have the following image, with a "large" object and 3 visible bright pixels:

enter image description here

What I do not understand:

Why do I count in the this image more pixels with brightness $\ge0$ (= 191688) than pixels are available (326$\cdot$294 = 95844). Also is not clear to me why so many pixels have brightness = 1.

image = ColorConvert[image, "Grayscale"]

dim = ImageDimensions[image]
{326, 294}

dim[[1]]*dim[[2]]
95844

Count[Flatten[ImageData[image]], a_ /; a >= 0]
191688

Count[Flatten[ImageData[image]], a_ /; a == 1]
95843

Accordingly, the histogram of the image is surprising:

Histogram[Flatten@ImageData@image, {0, 1.01, 0.01}, ScalingFunctions -> "Log"]

enter image description here

As next I wanted to measure the mean brightness center of the large object. Here I do not understand why the resultingImage includes the bright pixels visible in the original image and also has pixels with brightness $\ge0$, although the binarized image binImage containes only pixels with brightness of = 0 and = 1.

What am I doing wrong?

binImage = Binarize[image, 0.4]

enter image description here

Histogram[Flatten@ImageData@binImage, {0, 1.01, 0.01}, ScalingFunctions -> "Log"]

enter image description here

resultingImage = ImageMultiply[image, binImage]

enter image description here

Histogram[Flatten@ImageData@resultingImage, {0, 1.01, 0.01}, ScalingFunctions -> "Log"]

enter image description here

The following code measured the center of the large object and the three bright pixels:

meanValue = ComponentMeasurements[resultingImage, "Centroid"]
{1 -> {170.5, 231.5}, 2 -> {125.372, 172.731}, 3 -> {94.5, 70.5}, 4 -> {175.5, 70.5}}
$\endgroup$
3
  • 1
    $\begingroup$ Your image seems to have 2 channels, which is why Length@Flatten[ImageData[image]] is twice the value of dim[[1]]*dim[[2]] $\endgroup$
    – Jason B.
    Commented Mar 2, 2016 at 10:36
  • $\begingroup$ How could I solve that and why do have half of the pixles in image brightness=1? $\endgroup$
    – mrz
    Commented Mar 2, 2016 at 10:44
  • $\begingroup$ the second channel seems to be just flat white, so I say throw it out, see the answer below $\endgroup$
    – Jason B.
    Commented Mar 2, 2016 at 10:48

1 Answer 1

3
$\begingroup$

For some reason those 3 bright pixels are located in the second channel of your image, while the bright spot is in the first channel,

image = Import["https://i.sstatic.net/A4Gu8.png"];
{Image[ImageData[image][[All, All, 1]]], 
 Image[ImageData[image][[All, All, 2]]]}

enter image description here

So you could just throw out that second channel, which seems to have a flat brightness,

image = Image[ImageData[image][[All, All, 1]]]
ImageMultiply[image, Binarize[blackimage, 0.4]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you ... now I have looked into the original 4K image. It has only one channel. But when I cropped the image with xnview and saved it this strange 2 channel image was produced. You solved my problem. $\endgroup$
    – mrz
    Commented Mar 2, 2016 at 11:11
  • $\begingroup$ @mrz glad I could help $\endgroup$
    – Jason B.
    Commented Mar 2, 2016 at 11:11
  • $\begingroup$ You mean ColorSeparate? $\endgroup$
    – yode
    Commented Mar 5, 2016 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.