segmentation of balloons

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?".
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

No, I meant the output should be the column (x of the image) that has the maximum value.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: segmentation of balloons

Post by fmw42 »

Scale the image to one row. Then output to txt: and sort by value. In unix, I would do it as

Code: Select all

convert text_balloons_bw.png -scale x1! txt:- | tail -n +2 | sed 's/^\(.*\): .*gray[(]\(.*\)[)]$/\1 \2/g' | sort -r -k2

Code: Select all

577,0 99
576,0 99
548,0 99
530,0 99
526,0 99
505,0 99
504,0 99
497,0 99
481,0 99
452,0 99
445,0 99
556,0 98
554,0 98
519,0 98
514,0 98
513,0 98
495,0 98
470,0 98
441,0 98
578,0 97
552,0 97
544,0 97
537,0 97
446,0 97
443,0 97
431,0 97
426,0 97
267,0 97
266,0 97
265,0 97
553,0 96
536,0 96
535,0 96
531,0 96
524,0 96
520,0 96
425,0 96
579,0 95
477,0 95
468,0 95
430,0 95
423,0 95
421,0 95
261,0 95
231,0 95
534,0 94
476,0 94
422,0 94
296,0 94
264,0 94
260,0 94
254,0 94
232,0 94
208,0 94
551,0 93
533,0 93
469,0 93
414,0 93
358,0 93
355,0 93
352,0 93
329,0 93
328,0 93
327,0 93
297,0 93
295,0 93
249,0 93
214,0 93
207,0 93
197,0 93
580,0 92
557,0 92
523,0 92
509,0 92
494,0 92
493,0 92
363,0 92
362,0 92
361,0 92
359,0 92
357,0 92
356,0 92
335,0 92
334,0 92
311,0 92
305,0 92
304,0 92
289,0 92
277,0 92
272,0 92
270,0 92
263,0 92
262,0 92
248,0 92
247,0 92
230,0 92
224,0 92
222,0 92
213,0 92
212,0 92
209,0 92
206,0 92
195,0 92
194,0 92
187,0 92
532,0 91
525,0 91
508,0 91
397,0 91
391,0 91
390,0 91
389,0 91
373,0 91
360,0 91
333,0 91
312,0 91
294,0 91
288,0 91
280,0 91
279,0 91
278,0 91
271,0 91
269,0 91
268,0 91
256,0 91
255,0 91
253,0 91
238,0 91
233,0 91
225,0 91
223,0 91
196,0 91
190,0 91
189,0 91
188,0 91
186,0 91
550,0 90
442,0 90
420,0 90
415,0 90
396,0 90
349,0 90
348,0 90
339,0 90
338,0 90
326,0 90
306,0 90
298,0 90
281,0 90
273,0 90
259,0 90
258,0 90
246,0 90
239,0 90
234,0 90
228,0 90
215,0 90
205,0 90
202,0 90
185,0 90
184,0 90
419,0 89
418,0 89
413,0 89
404,0 89
398,0 89
388,0 89
382,0 89
379,0 89
378,0 89
354,0 89
317,0 89
310,0 89
274,0 89
245,0 89
243,0 89
242,0 89
241,0 89
240,0 89
237,0 89
236,0 89
235,0 89
229,0 89
221,0 89
220,0 89
219,0 89
218,0 89
210,0 89
204,0 89
203,0 89
201,0 89
183,0 89
549,0 88
411,0 88
400,0 88
399,0 88
392,0 88
374,0 88
369,0 88
368,0 88
365,0 88
364,0 88
353,0 88
345,0 88
344,0 88
340,0 88
325,0 88
324,0 88
323,0 88
316,0 88
299,0 88
290,0 88
287,0 88
244,0 88
226,0 88
217,0 88
216,0 88
211,0 88
198,0 88
193,0 88
191,0 88
182,0 88
559,0 87
543,0 87
417,0 87
410,0 87
408,0 87
407,0 87
406,0 87
387,0 87
370,0 87
350,0 87
343,0 87
322,0 87
282,0 87
275,0 87
257,0 87
192,0 87
181,0 87
558,0 86
542,0 86
412,0 86
409,0 86
405,0 86
403,0 86
394,0 86
385,0 86
372,0 86
351,0 86
337,0 86
336,0 86
330,0 86
318,0 86
303,0 86
286,0 86
276,0 86
227,0 86
180,0 86
384,0 85
383,0 85
377,0 85
371,0 85
341,0 85
313,0 85
285,0 85
283,0 85
252,0 85
251,0 85
200,0 85
199,0 85
416,0 84
402,0 84
395,0 84
393,0 84
386,0 84
381,0 84
380,0 84
347,0 84
346,0 84
342,0 84
309,0 84
293,0 84
292,0 84
250,0 84
179,0 84
320,0 83
319,0 83
300,0 83
178,0 83
401,0 82
376,0 82
332,0 82
321,0 82
314,0 82
307,0 82
302,0 82
291,0 82
284,0 82
177,0 82
375,0 81
366,0 81
331,0 81
367,0 80
315,0 80
308,0 80
301,0 80
176,0 80
582,0 8
175,0 78
174,0 76
173,0 74
172,0 69
583,0 6
584,0 5
585,0 4
587,0 3
586,0 3
171,0 26
170,0 24
588,0 2
545,0 113
546,0 111
562,0 110
561,0 110
473,0 110
581,0 11
563,0 109
439,0 109
564,0 108
517,0 108
491,0 108
472,0 108
438,0 108
437,0 108
565,0 107
547,0 107
539,0 107
538,0 107
516,0 107
511,0 107
500,0 107
474,0 107
456,0 107
450,0 107
566,0 106
518,0 106
461,0 106
457,0 106
449,0 106
434,0 106
433,0 106
567,0 105
540,0 105
528,0 105
512,0 105
475,0 105
568,0 104
521,0 104
490,0 104
486,0 104
482,0 104
471,0 104
460,0 104
455,0 104
448,0 104
432,0 104
572,0 103
571,0 103
570,0 103
569,0 103
560,0 103
515,0 103
510,0 103
501,0 103
488,0 103
487,0 103
483,0 103
451,0 103
436,0 103
435,0 103
427,0 103
529,0 102
522,0 102
499,0 102
492,0 102
485,0 102
480,0 102
479,0 102
467,0 102
464,0 102
462,0 102
454,0 102
574,0 101
573,0 101
555,0 101
541,0 101
527,0 101
507,0 101
506,0 101
503,0 101
502,0 101
498,0 101
496,0 101
484,0 101
478,0 101
463,0 101
459,0 101
440,0 101
429,0 101
428,0 101
424,0 101
575,0 100
489,0 100
466,0 100
465,0 100
458,0 100
453,0 100
447,0 100
444,0 100
589,0 1
99,0 0
98,0 0
97,0 0
96,0 0
95,0 0
94,0 0
93,0 0
92,0 0
91,0 0
90,0 0
9,0 0
89,0 0
88,0 0
87,0 0
86,0 0
85,0 0
84,0 0
83,0 0
82,0 0
81,0 0
80,0 0
8,0 0
79,0 0
78,0 0
77,0 0
76,0 0
75,0 0
74,0 0
73,0 0
72,0 0
71,0 0
70,0 0
7,0 0
69,0 0
68,0 0
67,0 0
66,0 0
65,0 0
64,0 0
63,0 0
62,0 0
61,0 0
60,0 0
6,0 0
599,0 0
598,0 0
597,0 0
596,0 0
595,0 0
594,0 0
593,0 0
592,0 0
591,0 0
590,0 0
59,0 0
58,0 0
57,0 0
56,0 0
55,0 0
54,0 0
53,0 0
52,0 0
51,0 0
50,0 0
5,0 0
49,0 0
48,0 0
47,0 0
46,0 0
45,0 0
44,0 0
43,0 0
42,0 0
41,0 0
40,0 0
4,0 0
39,0 0
38,0 0
37,0 0
36,0 0
35,0 0
34,0 0
33,0 0
32,0 0
31,0 0
30,0 0
3,0 0
29,0 0
28,0 0
27,0 0
26,0 0
25,0 0
24,0 0
23,0 0
22,0 0
21,0 0
20,0 0
2,0 0
19,0 0
18,0 0
17,0 0
169,0 0
168,0 0
167,0 0
166,0 0
165,0 0
164,0 0
163,0 0
162,0 0
161,0 0
160,0 0
16,0 0
159,0 0
158,0 0
157,0 0
156,0 0
155,0 0
154,0 0
153,0 0
152,0 0
151,0 0
150,0 0
15,0 0
149,0 0
148,0 0
147,0 0
146,0 0
145,0 0
144,0 0
143,0 0
142,0 0
141,0 0
140,0 0
14,0 0
139,0 0
138,0 0
137,0 0
136,0 0
135,0 0
134,0 0
133,0 0
132,0 0
131,0 0
130,0 0
13,0 0
129,0 0
128,0 0
127,0 0
126,0 0
125,0 0
124,0 0
123,0 0
122,0 0
121,0 0
120,0 0
12,0 0
119,0 0
118,0 0
117,0 0
116,0 0
115,0 0
114,0 0
113,0 0
112,0 0
111,0 0
110,0 0
11,0 0
109,0 0
108,0 0
107,0 0
106,0 0
105,0 0
104,0 0
103,0 0
102,0 0
101,0 0
100,0 0
10,0 0
1,0 0
0,0 0
or to get just the first one in the sorted list

Code: Select all

convert text_balloons_bw.png -scale x1! txt:- | tail -n +2 | sed 's/^\(.*\): .*gray[(]\(.*\)[)]$/\1 \2/g' | sort -r -k2 | head -n 1
577,0 99
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

Thanks Fred, that's what I wanted. I thought there might be a way for IM to spit it out, without using external tools, but that's fine.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: segmentation of balloons

Post by fmw42 »

This modification will eliminate the y=0 so only x and value:

Code: Select all

convert text_balloons_bw.png -scale x1! txt:- | tail -n +2 | sed 's/^\(.*\),.*: .*gray[(]\(.*\)[)]$/\1 \2/g' | sort -r -k2

Code: Select all

577 99
576 99
548 99
530 99
526 99
505 99
504 99
497 99
481 99
452 99
445 99
556 98
554 98
519 98
514 98
513 98
495 98
470 98
441 98
578 97
552 97
544 97
537 97
446 97
443 97
431 97
426 97
267 97
266 97
265 97
553 96
536 96
535 96
531 96
524 96
520 96
425 96
579 95
477 95
468 95
430 95
423 95
421 95
261 95
231 95
534 94
476 94
422 94
296 94
264 94
260 94
254 94
232 94
208 94
551 93
533 93
469 93
414 93
358 93
355 93
352 93
329 93
328 93
327 93
297 93
295 93
249 93
214 93
207 93
197 93
580 92
557 92
523 92
509 92
494 92
493 92
363 92
362 92
361 92
359 92
357 92
356 92
335 92
334 92
311 92
305 92
304 92
289 92
277 92
272 92
270 92
263 92
262 92
248 92
247 92
230 92
224 92
222 92
213 92
212 92
209 92
206 92
195 92
194 92
187 92
532 91
525 91
508 91
397 91
391 91
390 91
389 91
373 91
360 91
333 91
312 91
294 91
288 91
280 91
279 91
278 91
271 91
269 91
268 91
256 91
255 91
253 91
238 91
233 91
225 91
223 91
196 91
190 91
189 91
188 91
186 91
550 90
442 90
420 90
415 90
396 90
349 90
348 90
339 90
338 90
326 90
306 90
298 90
281 90
273 90
259 90
258 90
246 90
239 90
234 90
228 90
215 90
205 90
202 90
185 90
184 90
419 89
418 89
413 89
404 89
398 89
388 89
382 89
379 89
378 89
354 89
317 89
310 89
274 89
245 89
243 89
242 89
241 89
240 89
237 89
236 89
235 89
229 89
221 89
220 89
219 89
218 89
210 89
204 89
203 89
201 89
183 89
549 88
411 88
400 88
399 88
392 88
374 88
369 88
368 88
365 88
364 88
353 88
345 88
344 88
340 88
325 88
324 88
323 88
316 88
299 88
290 88
287 88
244 88
226 88
217 88
216 88
211 88
198 88
193 88
191 88
182 88
559 87
543 87
417 87
410 87
408 87
407 87
406 87
387 87
370 87
350 87
343 87
322 87
282 87
275 87
257 87
192 87
181 87
558 86
542 86
412 86
409 86
405 86
403 86
394 86
385 86
372 86
351 86
337 86
336 86
330 86
318 86
303 86
286 86
276 86
227 86
180 86
384 85
383 85
377 85
371 85
341 85
313 85
285 85
283 85
252 85
251 85
200 85
199 85
416 84
402 84
395 84
393 84
386 84
381 84
380 84
347 84
346 84
342 84
309 84
293 84
292 84
250 84
179 84
320 83
319 83
300 83
178 83
401 82
376 82
332 82
321 82
314 82
307 82
302 82
291 82
284 82
177 82
375 81
366 81
331 81
367 80
315 80
308 80
301 80
176 80
582 8
175 78
174 76
173 74
172 69
583 6
584 5
585 4
587 3
586 3
171 26
170 24
588 2
545 113
546 111
562 110
561 110
473 110
581 11
563 109
439 109
564 108
517 108
491 108
472 108
438 108
437 108
565 107
547 107
539 107
538 107
516 107
511 107
500 107
474 107
456 107
450 107
566 106
518 106
461 106
457 106
449 106
434 106
433 106
567 105
540 105
528 105
512 105
475 105
568 104
521 104
490 104
486 104
482 104
471 104
460 104
455 104
448 104
432 104
572 103
571 103
570 103
569 103
560 103
515 103
510 103
501 103
488 103
487 103
483 103
451 103
436 103
435 103
427 103
529 102
522 102
499 102
492 102
485 102
480 102
479 102
467 102
464 102
462 102
454 102
574 101
573 101
555 101
541 101
527 101
507 101
506 101
503 101
502 101
498 101
496 101
484 101
478 101
463 101
459 101
440 101
429 101
428 101
424 101
575 100
489 100
466 100
465 100
458 100
453 100
447 100
444 100
589 1
99 0
98 0
97 0
96 0
95 0
94 0
93 0
92 0
91 0
90 0
9 0
89 0
88 0
87 0
86 0
85 0
84 0
83 0
82 0
81 0
80 0
8 0
79 0
78 0
77 0
76 0
75 0
74 0
73 0
72 0
71 0
70 0
7 0
69 0
68 0
67 0
66 0
65 0
64 0
63 0
62 0
61 0
60 0
6 0
599 0
598 0
597 0
596 0
595 0
594 0
593 0
592 0
591 0
590 0
59 0
58 0
57 0
56 0
55 0
54 0
53 0
52 0
51 0
50 0
5 0
49 0
48 0
47 0
46 0
45 0
44 0
43 0
42 0
41 0
40 0
4 0
39 0
38 0
37 0
36 0
35 0
34 0
33 0
32 0
31 0
30 0
3 0
29 0
28 0
27 0
26 0
25 0
24 0
23 0
22 0
21 0
20 0
2 0
19 0
18 0
17 0
169 0
168 0
167 0
166 0
165 0
164 0
163 0
162 0
161 0
160 0
16 0
159 0
158 0
157 0
156 0
155 0
154 0
153 0
152 0
151 0
150 0
15 0
149 0
148 0
147 0
146 0
145 0
144 0
143 0
142 0
141 0
140 0
14 0
139 0
138 0
137 0
136 0
135 0
134 0
133 0
132 0
131 0
130 0
13 0
129 0
128 0
127 0
126 0
125 0
124 0
123 0
122 0
121 0
120 0
12 0
119 0
118 0
117 0
116 0
115 0
114 0
113 0
112 0
111 0
110 0
11 0
109 0
108 0
107 0
106 0
105 0
104 0
103 0
102 0
101 0
100 0
10 0
1 0
0 0
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

Actually the sed/sort snippet needs some fiddling because it lists two digits before three digits (99 before 113).

I also came up with these:

a. Is it possible to check for the color that is most scattered or "all over the place" (for a lack of a better word)? I want to identify the color of the background and then exclude it from the list of colors.

b. Or check the color that has the most continuous regions (i.e. the bubbles have the most continuous regions)? But not the most dominant color.

c. Maybe the background or the balloons can be found by taking note that the background takes the whole width, whereas the balloons take at most 80% of the width. Is there a way to check for these?

Edit: for clarity
Last edited by cso on 2017-06-10T17:21:02-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: segmentation of balloons

Post by fmw42 »

This will fix the sort issue.

Code: Select all

convert text_balloons_bw.png -scale x1! txt:- | tail -n +2 | sed 's/^\(.*\),.*: .*gray[(]\(.*\)[)]$/\1 \2/g' | sort -n -r -k 2,2

Code: Select all

545 113
546 111
562 110
561 110
473 110
563 109
439 109
564 108
517 108
491 108
472 108
438 108
437 108
565 107
547 107
539 107
538 107
516 107
511 107
500 107
474 107
456 107
450 107
566 106
518 106
461 106
457 106
449 106
434 106
433 106
567 105
540 105
528 105
512 105
475 105
568 104
521 104
490 104
486 104
482 104
471 104
460 104
455 104
448 104
432 104
572 103
571 103
570 103
569 103
560 103
515 103
510 103
501 103
488 103
487 103
483 103
451 103
436 103
435 103
427 103
529 102
522 102
499 102
492 102
485 102
480 102
479 102
467 102
464 102
462 102
454 102
574 101
573 101
555 101
541 101
527 101
507 101
506 101
503 101
502 101
498 101
496 101
484 101
478 101
463 101
459 101
440 101
429 101
428 101
424 101
575 100
489 100
466 100
465 100
458 100
453 100
447 100
444 100
577 99
576 99
548 99
530 99
526 99
505 99
504 99
497 99
481 99
452 99
445 99
556 98
554 98
519 98
514 98
513 98
495 98
470 98
441 98
578 97
552 97
544 97
537 97
446 97
443 97
431 97
426 97
267 97
266 97
265 97
553 96
536 96
535 96
531 96
524 96
520 96
425 96
579 95
477 95
468 95
430 95
423 95
421 95
261 95
231 95
534 94
476 94
422 94
296 94
264 94
260 94
254 94
232 94
208 94
551 93
533 93
469 93
414 93
358 93
355 93
352 93
329 93
328 93
327 93
297 93
295 93
249 93
214 93
207 93
197 93
580 92
557 92
523 92
509 92
494 92
493 92
363 92
362 92
361 92
359 92
357 92
356 92
335 92
334 92
311 92
305 92
304 92
289 92
277 92
272 92
270 92
263 92
262 92
248 92
247 92
230 92
224 92
222 92
213 92
212 92
209 92
206 92
195 92
194 92
187 92
532 91
525 91
508 91
397 91
391 91
390 91
389 91
373 91
360 91
333 91
312 91
294 91
288 91
280 91
279 91
278 91
271 91
269 91
268 91
256 91
255 91
253 91
238 91
233 91
225 91
223 91
196 91
190 91
189 91
188 91
186 91
550 90
442 90
420 90
415 90
396 90
349 90
348 90
339 90
338 90
326 90
306 90
298 90
281 90
273 90
259 90
258 90
246 90
239 90
234 90
228 90
215 90
205 90
202 90
185 90
184 90
419 89
418 89
413 89
404 89
398 89
388 89
382 89
379 89
378 89
354 89
317 89
310 89
274 89
245 89
243 89
242 89
241 89
240 89
237 89
236 89
235 89
229 89
221 89
220 89
219 89
218 89
210 89
204 89
203 89
201 89
183 89
549 88
411 88
400 88
399 88
392 88
374 88
369 88
368 88
365 88
364 88
353 88
345 88
344 88
340 88
325 88
324 88
323 88
316 88
299 88
290 88
287 88
244 88
226 88
217 88
216 88
211 88
198 88
193 88
191 88
182 88
559 87
543 87
417 87
410 87
408 87
407 87
406 87
387 87
370 87
350 87
343 87
322 87
282 87
275 87
257 87
192 87
181 87
558 86
542 86
412 86
409 86
405 86
403 86
394 86
385 86
372 86
351 86
337 86
336 86
330 86
318 86
303 86
286 86
276 86
227 86
180 86
384 85
383 85
377 85
371 85
341 85
313 85
285 85
283 85
252 85
251 85
200 85
199 85
416 84
402 84
395 84
393 84
386 84
381 84
380 84
347 84
346 84
342 84
309 84
293 84
292 84
250 84
179 84
320 83
319 83
300 83
178 83
401 82
376 82
332 82
321 82
314 82
307 82
302 82
291 82
284 82
177 82
375 81
366 81
331 81
367 80
315 80
308 80
301 80
176 80
175 78
174 76
173 74
172 69
171 26
170 24
581 11
582 8
583 6
584 5
585 4
587 3
586 3
588 2
589 1
99 0
98 0
97 0
96 0
95 0
94 0
93 0
92 0
91 0
90 0
9 0
89 0
88 0
87 0
86 0
85 0
84 0
83 0
82 0
81 0
80 0
8 0
79 0
78 0
77 0
76 0
75 0
74 0
73 0
72 0
71 0
70 0
7 0
69 0
68 0
67 0
66 0
65 0
64 0
63 0
62 0
61 0
60 0
6 0
599 0
598 0
597 0
596 0
595 0
594 0
593 0
592 0
591 0
590 0
59 0
58 0
57 0
56 0
55 0
54 0
53 0
52 0
51 0
50 0
5 0
49 0
48 0
47 0
46 0
45 0
44 0
43 0
42 0
41 0
40 0
4 0
39 0
38 0
37 0
36 0
35 0
34 0
33 0
32 0
31 0
30 0
3 0
29 0
28 0
27 0
26 0
25 0
24 0
23 0
22 0
21 0
20 0
2 0
19 0
18 0
17 0
169 0
168 0
167 0
166 0
165 0
164 0
163 0
162 0
161 0
160 0
16 0
159 0
158 0
157 0
156 0
155 0
154 0
153 0
152 0
151 0
150 0
15 0
149 0
148 0
147 0
146 0
145 0
144 0
143 0
142 0
141 0
140 0
14 0
139 0
138 0
137 0
136 0
135 0
134 0
133 0
132 0
131 0
130 0
13 0
129 0
128 0
127 0
126 0
125 0
124 0
123 0
122 0
121 0
120 0
12 0
119 0
118 0
117 0
116 0
115 0
114 0
113 0
112 0
111 0
110 0
11 0
109 0
108 0
107 0
106 0
105 0
104 0
103 0
102 0
101 0
100 0
10 0
1 0
0 0
The only way to get continuous regions that I know is via connected-components. That is its purpose.

The only way I know to get the background color is too find the histogram color with the most counts, assuming the background color has a larger total area than any other color. So you can list the histogram and sort it by count.

P.S. Or just take the list of connected components and use the first entry, since it is sorted already be largest area first.
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

I edited my question after your post.
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

The sorting now works fine, thanks.

But connected components in only for thresholded images, right?

Your second post in this thread is what an implementation of the histogram color with the most counts right? The posterization doesn't work well with other images, e.g. a light gray that gets mixed with a white bg.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: segmentation of balloons

Post by fmw42 »

cso wrote: But connected components in only for thresholded images, right?
No, it works fine if you do not have too many colors or lots of fine detail such that you exceed 65536 regions on Q16 ImageMagick
cso wrote:Your second post in this thread is what an implementation of the histogram color with the most counts right? The posterization doesn't work well with other images, e.g. a light gray that gets mixed with a white bg.
No, my second post used your color image.

I did not posterize it. I simply reduced the number of colors using +dither -colors 8. I did that because you have a jpg image and its compression does not preserve large blocks of colors without potential changing the color values slightly. Therefore it might have exceeded the max number of regions of 65535 for Q16.

If I use 256 colors, then I get

Code: Select all

convert text_balloons.jpg +dither -colors 256 \
> -define connected-components:verbose=true \
> -define connected-components:area-threshold=5000 \
> -define connected-components:mean-color=true \
> -connected-components 8 \
> text_balloons_ccl2.png
convert: too many objects `text_balloons.jpg' @ error/vision.c/ConnectedComponentsImage/438.

Which shows that even for 256 colors with a jpeg, you get too many regions.

The same for 128 colors. 64 colors did not error, but was taking too long.

32 colors works OK

Code: Select all

convert text_balloons.jpg +dither -colors 32 \
> -define connected-components:verbose=true \
> -define connected-components:area-threshold=5000 \
> -define connected-components:mean-color=true \
> -connected-components 8 \
> text_balloons_ccl2.png
Objects (id: bounding-box centroid area mean-color):
  4720: 600x708+0+120 257.3,507.3 228315 srgb(252,252,252)
  4809: 412x204+173+133 376.3,236.0 79836 srgb(41,140,251)
  0: 520x120+0+0 222.8,49.8 47317 srgb(244,244,238)
  25915: 382x115+183+493 392.0,535.9 29530 srgb(41,140,251)
  37482: 301x99+78+637 232.1,686.2 27717 srgb(231,230,235)
  42455: 585x64+15+826 276.7,860.4 27319 srgb(252,252,252)
  26067: 415x122+170+506 353.6,593.9 21589 srgb(41,140,251)
  23299: 355x63+78+346 258.2,377.2 21067 srgb(231,230,235)
  42399: 600x74+0+826 336.4,866.2 16642 srgb(252,252,252)
  2604: 464x74+128+48 389.0,101.3 13367 srgb(235,246,251)
  1: 128x120+472+0 549.9,48.9 9977 srgb(252,252,252)
  41817: 160x64+422+746 500.7,778.1 8440 srgb(41,140,251)
But you have some other color regions showing as there are still small areas of white or black in the image inside the larger ones. So you probably should iterate a second time as I did in one of my other posts in your topic.

The main issue is how big to make the area threshold. That must be smaller than the size of the smallest area you want to preserve or find. That will be image dependent.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: segmentation of balloons

Post by snibgo »

@cso: How are you capturing these images? They are graphic images, with areas of flat colour, but saved as jpg which uses compression designed for photographs, and changes colours. So the first task is to convert the image back to flat colours.

The job would be easier if the screengrabs were saved as png, which is lossless.
snibgo's IM pages: im.snibgo.com
cso
Posts: 28
Joined: 2017-06-09T19:10:21-07:00
Authentication code: 1151

Re: segmentation of balloons

Post by cso »

By posterization I actually meant color quantization.
Thanks for the explanation Fred, I will run some more tests and probably come back for more questions.
@snibgo: The actual images are png. I will experiment.
Last edited by cso on 2017-06-12T05:44:43-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: segmentation of balloons

Post by fmw42 »

The images that one can download are JPG. So you should find a service that allows you to upload PNG without converting to JPG. If your images are PNG, you may still have many more colors than you want. You can check how many colors you actually have in your images using either the histogram or -unique-colors. See http://www.imagemagick.org/Usage/quantize/#extract. If you have few enough colors and not too many isolated regions of those colors, then you might not need to use the color quantization.
Post Reply