Count amount of non-continuous blocks in an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Count amount of non-continuous blocks in an image

Post by snibgo »

"+antialias" is a setting to prevent operations from anti-aliasing pixels. It does not remove anti-aliasing.

I pointed you to a thread https://www.imagemagick.org/discourse-s ... =1&t=37649 where I show a command to remove anti-aliasing. For example (Windows BAT syntax):

Code: Select all

magick ^
  pen.png ^
  -alpha off ^
  +write mpr:INP ^
  -define convolve:scale="50%%^!" -bias 50%% ^
  -define morphology:compose=Lighten ^
  -channel RGB ^
  -morphology Convolve "Sobel:>"  ^
  -solarize 50%% -level 50,0%% ^
  -negate ^
  +channel ^
  -fill Black +opaque White ^
  mpr:INP ^
  +swap ^
  -alpha off ^
  -compose CopyAlpha -composite ^
  -background White ^
  -compose Over ^
  -layers Flatten ^
  -unique-colors +write mpr:UNIQ ^
  -format "Unique: %%w\n" +write info: ^
  +delete ^
  mpr:INP ^
  +dither -remap mpr:UNIQ ^
  pen_r.png
Image
pen_r.png contains two colours, black and greeny-blue. There are seven green-blue areas. I don't know why you say:
Peggy wrote:6 objects expected.

Code: Select all

magick ^
  pen_r.png ^
  -background Black -layers Flatten -alpha off ^
  -define connected-components:verbose=true ^
  -define connected-components:area-threshold=100 ^
  -connected-components 4 -auto-level ^
  pen_ok.png

  0: 512x512+0+0 248.2,258.8 210203 srgb(0,0,0)
  1: 303x303+209+4 358.7,157.2 18554 srgb(5.63363%,99.9954%,71.3634%)
  6: 320x239+0+269 144.3,404.9 12992 srgb(5.63363%,99.9954%,71.3634%)
  3: 190x189+251+47 345.8,141.2 6054 srgb(0,0,0)
  4: 189x190+280+75 374.0,169.5 5882 srgb(0,0,0)
  7: 70x126+49+325 85.3,387.7 2498 srgb(5.63363%,99.9954%,71.3634%)
  8: 70x126+201+325 233.4,388.4 2444 srgb(5.63363%,99.9954%,71.3634%)
  2: 60x60+436+20 467.1,48.0 1694 srgb(0,0,0)
  5: 53x53+228+235 250.2,265.1 1343 srgb(0,0,0)
  11: 14x14+185+405 191.5,411.8 161 srgb(5.63363%,99.9954%,71.3634%)
  9: 14x14+121+405 127.4,411.8 160 srgb(5.63363%,99.9954%,71.3634%)
  10: 14x14+153+405 159.4,411.9 159 srgb(5.63363%,99.9954%,71.3634%)
As expected, seven components are not black.
snibgo's IM pages: im.snibgo.com

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-11T05:11:11-07:00
"+antialias" is a setting to prevent operations from anti-aliasing pixels. It does not remove anti-aliasing.

I pointed you to a thread https://www.imagemagick.org/discourse-s ... =1&t=37649 where I show a command to remove anti-aliasing. For example (Windows BAT syntax):

Code: Select all

magick ^
  pen.png ^
  -alpha off ^
  +write mpr:INP ^
  -define convolve:scale="50%%^!" -bias 50%% ^
  -define morphology:compose=Lighten ^
  -channel RGB ^
  -morphology Convolve "Sobel:>"  ^
  -solarize 50%% -level 50,0%% ^
  -negate ^
  +channel ^
  -fill Black +opaque White ^
  mpr:INP ^
  +swap ^
  -alpha off ^
  -compose CopyAlpha -composite ^
  -background White ^
  -compose Over ^
  -layers Flatten ^
  -unique-colors +write mpr:UNIQ ^
  -format "Unique: %%w\n" +write info: ^
  +delete ^
  mpr:INP ^
  +dither -remap mpr:UNIQ ^
  pen_r.png
pen_r.png contains two colours, black and greeny-blue. There are seven green-blue areas. I don't know why you say:
Peggy wrote:6 objects expected.
Yes, I miscounted. It's 7 objects,

Sorry, my English is bad, forgot the vocabulary for anti-aliasing. I tried to run the command from linux but couldn't get it done. That's why I asked for changing windows bat to linux command on that thread.

Here is the error message, I just simply removed ^ from the command.

Code: Select all

convert: unrecognized compose operator `CopyAlpha' @ error/convert.c/ConvertImageCommand/1100.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Count amount of non-continuous blocks in an image

Post by fmw42 »

For Imagemgick 6 on Unix-like systems, change ^ to \, change magick to convert, change %% to %, change CopyAlpha to CopyOpacity

Code: Select all

convert \
  pen.png \
  -alpha off \
  +write mpr:INP \
  -define convolve:scale="50%!" -bias 50% \
  -define morphology:compose=Lighten \
  -channel RGB \
  -morphology Convolve "Sobel:>"  \
  -solarize 50% -level 50,0% \
  -negate \
  +channel \
  -fill Black +opaque White \
  mpr:INP \
  +swap \
  -alpha off \
  -compose CopyOpacity -composite \
  -background White \
  -compose Over \
  -layers Flatten \
  -unique-colors +write mpr:UNIQ \
  -format "Unique: %w\n" +write info: \
  +delete \
  mpr:INP \
  +dither -remap mpr:UNIQ \
  pen_r.png

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

fmw42 wrote:
2020-03-11T23:04:12-07:00
For Imagemgick 6 on Unix-like systems, change ^ to \, change magick to convert, change %% to %, change CopyAlpha to CopyOpacity
change CopyAlpha to CopyOpacity <-- This one worked, thank you thank you!

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-11T05:11:11-07:00
"+antialias" is a setting to prevent operations from anti-aliasing pixels. It does not remove anti-aliasing.

I pointed you to a thread https://www.imagemagick.org/discourse-s ... =1&t=37649 where I show a command to remove anti-aliasing. For example (Windows BAT syntax):

Code: Select all

magick ^
  pen.png ^
  -alpha off ^
  +write mpr:INP ^
  -define convolve:scale="50%%^!" -bias 50%% ^
  -define morphology:compose=Lighten ^
  -channel RGB ^
  -morphology Convolve "Sobel:>"  ^
  -solarize 50%% -level 50,0%% ^
  -negate ^
  +channel ^
  -fill Black +opaque White ^
  mpr:INP ^
  +swap ^
  -alpha off ^
  -compose CopyAlpha -composite ^
  -background White ^
  -compose Over ^
  -layers Flatten ^
  -unique-colors +write mpr:UNIQ ^
  -format "Unique: %%w\n" +write info: ^
  +delete ^
  mpr:INP ^
  +dither -remap mpr:UNIQ ^
  pen_r.png
I got some different results after some attempts with anti-aliasing removal command.

Image 1

Origin:
Image

Result: Unique: 3
Image





Image 2

Origin:
Image

Result: Unique: 3
Image






Image 3

Origin:
Image

Result: Unique: 4
Image






Image 4

Origin:
Image

Result: Unique: 8
Image


But some of images had really good result after anti-aliasing got removed, I could get correct objects amount with -connected-commponents those were incorrect before, like the image below:


Origin:
Image

Result: Unique: 2, 3 objects counted. That was 4 objects before anti-aliasing removal.
Image



My another question is how do I decide backgound color for the image? I tried the change -fill black with -fill Red but nothing changed.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Count amount of non-continuous blocks in an image

Post by snibgo »

The command I showed writes "Unique: N" where N is an integer. This is the number of unique colours found after de-anti-aliasing. That number is not important to you.

What number is important to you? I think you want to count the connected components that are not the transparent background colour. Is that right? What result do you want? Just a number, or a number and an image, or what?

For the "png tree" image, which has a transparent white background, running my two commands gives seven non-white connected components. Is that the result you want?

The "six flower" image has a transparent black background and a transparent white background. Running my two commands gives six connected components that are neither white nor black. Is that the result you want?
Peggy wrote:My another question is how do I decide backgound color for the image?
You have images with transparent backgrounds of different colours, sometimes within a single image. I suggest you regularise you images to use the same colour, perhaps by starting with "-background #010200000000 -alpha Background". This will change the transparent colour to one that the image probably doesn't already have.
snibgo's IM pages: im.snibgo.com

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-12T06:37:07-07:00
The command I showed writes "Unique: N" where N is an integer. This is the number of unique colours found after de-anti-aliasing. That number is not important to you.
Some infomation wasn't saved for my last reply, sorry about that. I did write connected-component result after unique number for each image but it's gone. What I need is only amount of connected components, nothing else. Some results for the previous imags were wong, Seems to my results were not the same as yours, I am not pretty sure about that. Regularise images to use the same colour would be a good idea, I'll think about it. Thank you for your suggestion.

Here are the images those can't count the result correctly with my platform. I used your commands and start with -background #010200000000 -alpha Background:

IM version: ImageMagick 6.9.6-8 Q16 x86_64
OS: Linux Alpine.



Image 1:
Image
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  52: 400x202+0+198 200.4,299.2 78143 srgb(1,0,0)
  0: 400x199+0+0 200.0,98.7 76319 srgb(1,0,0)
  41: 95x6+259+162 304.0,164.6 515 srgb(209,176,42)
  9: 75x7+95+62 130.7,65.0 507 srgb(6,158,219)
  104: 80x5+95+323 133.7,325.0 392 srgb(77,140,64)
  10: 79x5+95+69 133.4,71.0 389 srgb(0,106,154)
  108: 65x5+95+339 126.0,341.0 315 srgb(150,201,61)
  7: 63x5+95+52 125.0,54.0 305 srgb(0,106,154)
  81: 92x3+199+271 244.7,272.0 273 srgb(165,142,49)
  28: 181x2+110+125 215.1,125.7 272 srgb(0,106,154)
  35: 73x3+204+148 239.5,149.0 216 srgb(0,106,154)
  70: 71x3+204+245 238.5,246.0 210 srgb(77,140,64)
  55: 198x1+0+199 98.5,199.0 198 srgb(77,140,64)
  57: 198x1+202+199 300.5,199.0 198 srgb(209,176,42)
  54: 198x1+202+198 300.5,198.0 198 srgb(165,142,49)
  8: 67x3+95+57 127.2,58.0 196 srgb(6,158,219)
  14: 90x2+98+92 142.3,92.5 179 srgb(0,106,154)
  98: 88x2+97+308 140.5,308.5 176 srgb(77,140,64)
  13: 88x2+97+87 140.3,87.5 175 srgb(0,106,154)
  110: 60x3+95+344 123.7,345.0 175 srgb(77,140,64)
  101: 86x2+96+314 138.3,314.5 171 srgb(77,140,64)
  12: 85x2+96+81 137.8,81.5 169 srgb(0,106,154)
  34: 79x2+203+140 242.0,140.5 158 srgb(0,106,154)
  107: 76x2+95+328 132.3,328.5 151 srgb(150,201,61)
22 objects found, 6 objects expected.






Image 2:
Image
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  0: 512x512+0+0 255.4,254.4 257708 srgb(1,0,0)
  157: 450x2+32+346 256.5,346.5 898 srgb(47,53,68)
  161: 468x1+22+360 255.5,360.0 468 srgb(47,53,68)
  160: 461x1+26+355 256.0,355.0 461 srgb(48,54,68)
  159: 457x1+28+352 256.0,352.0 457 srgb(47,53,68)
  158: 454x1+30+350 256.5,350.0 454 srgb(48,54,68)
  15: 44x7+285+216 305.5,219.1 293 srgb(47,53,68)
  129: 101x2+136+319 186.0,319.5 200 srgb(47,53,68)
  114: 65x3+369+308 401.3,309.0 191 srgb(47,53,68)
  5: 21x10+286+177 294.7,181.8 182 srgb(47,53,68)
  152: 182x1+120+334 210.5,334.0 182 srgb(47,53,68)
  39: 74x2+304+248 340.5,248.5 148 srgb(47,53,68)
  66: 65x2+110+276 142.0,276.5 130 srgb(47,53,68)
  10: 27x5+286+193 298.5,195.0 130 srgb(48,54,68)
  148: 127x1+126+330 189.0,330.0 127 srgb(47,53,68)
  60: 23x5+193+271 204.0,273.0 115 srgb(47,53,68)
15 objects founds, 1 object expected.




Image 3:
Image
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  0: 1027x327+0+0 510.3,163.2 329500 srgb(1,0,0)
  2: 41x111+586+104 594.9,154.6 1888 srgb(51,51,51)
  74: 116x13+632+153 688.9,158.6 1408 srgb(51,51,51)
  77: 116x9+758+155 815.5,159.0 1044 srgb(136,176,75)
  1: 58x14+518+104 546.5,110.5 812 srgb(51,51,51)
  72: 116x5+758+150 815.1,152.3 493 srgb(51,51,51)
  75: 16x13+252+154 259.5,160.0 208 srgb(51,51,51)
  78: 116x5+758+164 797.7,164.9 180 srgb(51,51,51)
  133: 77x2+652+204 690.0,204.5 152 srgb(51,51,51)
  76: 16x9+394+155 401.5,159.0 144 srgb(51,51,51)
9 objects found, 7 objects expected.



Image 4:
Image
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  0: 800x800+0+0 399.5,399.5 640000 srgb(0,0,0)
1 object found, 14 objects expected.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Count amount of non-continuous blocks in an image

Post by magick »

Try this command:

Code: Select all

$ convert ZJLp03D.png -define connected-components:verbose=true -define connected-components:area-threshold=100 -connected-components 8 -normalize birds.png
Objects (id: bounding-box centroid area mean-color):
  0: 800x800+0+0 399.6,398.8 628975 srgba(0,0,0,0.104711)
  1787: 52x69+337+395 358.4,426.1 1345 srgba(0,0,0,55.7037)
  4461: 51x68+710+699 739.9,735.3 1120 srgba(0,0,0,68.8416)
  11: 51x60+81+48 107.7,77.9 986 srgba(0,0,0,75.6412)
  1842: 51x60+179+401 205.7,430.9 986 srgba(0,0,0,75.6412)
  2581: 37x62+600+499 615.3,526.8 935 srgba(0,0,0,83.6419)
  365: 77x46+111+168 148.0,192.0 847 srgba(0,0,0,94.3547)
  2539: 77x46+494+497 531.0,521.0 847 srgba(0,0,0,94.3547)
  1353: 91x23+129+361 173.4,368.7 712 srgba(0,0,0,127.029)
  3554: 91x23+620+615 664.4,622.7 712 srgba(0,0,0,127.029)
  4288: 36x49+567+675 582.0,697.1 686 srgba(0,0,0,116.379)
  464: 74x41+198+177 234.0,191.2 579 srgba(0,0,0,161.625)
  3194: 78x20+309+545 346.8,551.7 573 srgba(0,0,0,142.851)
  1047: 48x32+242+213 263.7,228.4 466 srgba(0,0,0,188.779)
  3620: 25x26+563+617 572.9,629.5 231 srgba(0,0,0,512.992)

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

magick wrote:
2020-03-13T02:47:00-07:00
Try this command:
Thank you for the information. After I tested your command, some images couldn't get good result. such as:
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  0: 512x512+0+0 248.2,258.7 208965 srgba(71,112,76,0)
  7: 303x303+209+4 357.9,157.2 17253 srgba(12,213,152,1)
  253: 319x239+0+269 142.5,406.5 12690 srgba(12,213,152,1)
  63: 190x189+251+47 345.5,141.0 5882 srgba(71,112,76,0)
  118: 189x190+280+75 374.0,169.5 5882 srgba(71,112,76,0)
  604: 70x126+49+325 85.2,387.2 2460 srgba(12,213,152,1)
  609: 70x126+201+325 233.5,387.9 2393 srgba(12,213,152,1)
  48: 61x61+435+20 466.8,48.2 1820 srgba(71,112,76,0)
  168: 54x54+228+234 250.9,264.5 1418 srgba(71,112,76,0)
  1080: 241x1+39+492 159.0,492.0 241 srgba(0,221,149,0.0352941)
  33: 204x204+234+10 335.5,111.5 204 srgba(0,221,149,0.0352941)
  125: 204x204+302+78 403.5,179.5 204 srgba(0,221,149,0.0352941)
  37: 203x203+235+11 336.0,112.0 203 srgba(10,214,151,0.741176)
  124: 203x203+302+78 403.0,179.0 203 srgba(11,213,152,0.764706)
  97: 190x173+251+64 345.5,157.0 190 srgba(9,215,153,0.180392)
  117: 173x190+279+75 358.0,169.5 190 srgba(9,215,153,0.180392)
  98: 174x174+268+64 354.5,150.5 174 srgba(11,213,151,0.921569)
  114: 174x174+278+74 364.5,160.5 174 srgba(11,213,151,0.921569)
  134: 173x173+297+92 383.0,178.0 173 srgba(10,213,151,0.443137)
  60: 173x173+251+46 337.0,132.0 173 srgba(10,213,151,0.443137)
  592: 1x161+304+308 304.0,388.0 161 srgba(10,213,151,0.443137)
  591: 1x161+15+308 15.0,388.0 161 srgba(0,221,149,0.0352941)
  777: 14x14+185+405 191.5,411.8 161 srgba(12,213,152,1)
  593: 1x160+319+308 319.0,387.5 160 srgba(11,213,151,0.643137)
  763: 14x14+121+405 127.4,411.8 160 srgba(12,213,152,1)
  770: 14x14+153+405 159.4,411.9 159 srgba(12,213,152,1)
  365: 145x1+39+283 111.0,283.0 145 srgba(10,213,152,0.556863)
  242: 145x1+39+268 111.0,268.0 145 srgba(10,213,151,0.443137)

For the birds.png this command does the job:

Code: Select all

magick birds.png -background Black -layers Flatten -alpha off -define connected-components:verbose=true -define connected-components:area-threshold=100 -connected-components 4 -auto-level birds.png
This command was provied by @fmw42. If the image is uncompressed and doesn't have anti-aliasing, the script works perfectly for me. @snibgo is helping me on anti-aliasing removal, I'm stuck with it.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Count amount of non-continuous blocks in an image

Post by snibgo »

@Peggy: Your results are very different from mine. Your images also look wrong, with horizontal bands.

Please show the command you used, for example for the "six-flower" image. Perhaps the conversion to bash has introduced an error.
snibgo's IM pages: im.snibgo.com

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-13T07:09:12-07:00
@Peggy: Your results are very different from mine. Your images also look wrong, with horizontal bands.

Please show the command you used, for example for the "six-flower" image. Perhaps the conversion to bash has introduced an error.
Sorry for not getting back to you sooner. I'll re-install my IM to ubuntu OS and use newest version of IM and than report the result. Thank you.

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-13T07:09:12-07:00
@Peggy: Your results are very different from mine. Your images also look wrong, with horizontal bands.

Please show the command you used, for example for the "six-flower" image. Perhaps the conversion to bash has introduced an error.

After upgraded IM to IM7, the results look pretty good.

version:

Code: Select all

Version: ImageMagick 7.0.10-0 Q16 x86_64 2020-03-16 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): freetype jng jpeg png x xml zlib
Command

Code: Select all

convert \
  mountain.png \
  -alpha off \
  +write mpr:INP \
  -define convolve:scale="50%!" -bias 50% \
  -define morphology:compose=Lighten \
  -channel RGB \
  -morphology Convolve "Sobel:>"  \
  -solarize 50% -level 50,0% \
  -negate \
  +channel \
  -fill Black +opaque White \
  mpr:INP \
  +swap \
  -alpha off \
  -compose CopyOpacity -composite \
  -background White \
  -compose Over \
  -layers Flatten \
  -unique-colors +write mpr:UNIQ \
  -format "Unique: %w\n" +write info: \
  +delete \
  mpr:INP \
  +dither -remap mpr:UNIQ \
  mountain_ok.png
Results for mountain and flower
Image

Code: Select all

Objects (id: bounding-box centroid area mean-color):
  0: 512x512+0+0 255.1,246.5 209769 srgb(71,112,76)
  1: 469x211+22+151 262.4,298.5 35794 srgb(48,54,68)
  20: 88x160+216+172 252.8,247.7 8811 srgb(71,112,76)
  148: 92x84+301+262 346.6,309.7 3318 srgb(71,112,76)
  183: 88x73+53+273 102.2,316.3 2918 srgb(71,112,76)
  86: 31x81+166+235 181.5,283.1 1095 srgb(71,112,76)
  290: 32x30+413+308 431.5,326.0 439 srgb(71,112,76)

Image

Code: Select all

  
  Objects (id: bounding-box centroid area mean-color):
  1: 134x172+0+26 49.3,100.7 14828 srgb(0,0,0)
  22: 134x171+266+201 349.7,296.4 14815 srgb(0,0,0)
  5: 133x171+267+26 349.7,100.6 14799 srgb(0,0,0)
  19: 132x171+0+201 49.2,296.5 14755 srgb(0,0,0)
  28: 400x28+0+372 199.5,385.5 11200 srgb(255,255,255)
  2: 107x173+94+26 146.5,106.9 10794 srgb(6,158,219)
  18: 105x173+200+199 252.4,290.2 10786 srgb(165,142,49)
  8: 199x84+201+157 305.6,198.5 10784 srgb(209,176,42)
  7: 199x84+0+157 93.4,198.6 10775 srgb(77,140,64)
  4: 105x172+200+26 252.5,106.9 10766 srgb(0,106,154)
  17: 106x173+94+199 146.3,290.2 10757 srgb(150,201,61)
  0: 400x26+0+0 199.5,12.5 10400 srgb(255,255,255)
  27: 192x97+104+275 199.3,345.0 6155 srgb(0,0,0)
  3: 192x96+104+26 199.6,51.9 6149 srgb(0,0,0)
  20: 57x33+139+201 167.2,217.1 389 srgb(0,0,0)
  11: 57x33+204+164 231.8,180.0 381 srgb(0,0,0)
  24: 8x64+196+204 199.4,235.6 378 srgb(0,0,0)
  6: 8x64+196+130 199.5,161.4 378 srgb(0,0,0)
  23: 55x32+205+202 231.9,217.2 361 srgb(0,0,0)
  12: 54x31+141+165 167.2,180.0 350 srgb(0,0,0)
For the flower, there are extra white blocks at the top and bottom. is that the same as yours?

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-13T07:09:12-07:00
@Peggy: Your results are very different from mine. Your images also look wrong, with horizontal bands.

Please show the command you used, for example for the "six-flower" image. Perhaps the conversion to bash has introduced an error.
@snibgo Could you please help me to see that why my flower image has white blocks? Thank you.

Peggy
Posts: 33
Joined: 2020-03-02T22:31:47-07:00
Authentication code: 1152

Re: Count amount of non-continuous blocks in an image

Post by Peggy »

snibgo wrote:
2020-03-13T07:09:12-07:00
@Peggy: Your results are very different from mine. Your images also look wrong, with horizontal bands.

Please show the command you used, for example for the "six-flower" image. Perhaps the conversion to bash has introduced an error.
@snibgo Could you please help me to see that why my flower image has white blocks? Should I re-install my IM to version like yours? I don't know why, I'm still using convert to run the script, it's not the same as yours to use magick as the command.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Count amount of non-continuous blocks in an image

Post by snibgo »

For the flower image, the input has transparent black pixels, with bands of transparent white at top and bottom. We can see these with:

Code: Select all

magick sixFlower.png -alpha off sixflower_na.png
The result sixflower_na.png is:
Image

The connected-component list correctly shows six components that are neither black nor white.

You now use a v7 version of IM. I suggest you should use "magick" instead of "convert".
snibgo's IM pages: im.snibgo.com

Locked