|
47 | 47 | //| |
48 | 48 | //| The name of the function comes from |
49 | 49 | //| `OpenMV <https://docs.openmv.io/library/omv.image.html#image.Image.morph>`_. |
| 50 | +//| ImageMagick calls this "-morphology" ("-morph" is an unrelated image blending |
| 51 | +//| algorithm). PIL calls this "kernel". |
50 | 52 | //| |
51 | 53 | //| For background on how this kind of image processing, including some |
52 | 54 | //| useful ``weights`` values, see `wikipedia's article on the |
@@ -289,33 +291,37 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = { |
289 | 291 | }; |
290 | 292 |
|
291 | 293 | //| def mix( |
292 | | -//| bitmap: displayio.Bitmap, weights: Sequence[int], mask: displayio.Bitmap | None = None |
| 294 | +//| bitmap: displayio.Bitmap, |
| 295 | +//| weights: ChannelScale | ChannelScaleOffset | ChannelMixer | ChannelMixerOffset, |
| 296 | +//| mask: displayio.Bitmap | None = None, |
293 | 297 | //| ) -> displayio.Bitmap: |
294 | 298 | //| """Perform a channel mixing operation on the bitmap |
295 | 299 | //| |
296 | 300 | //| This is similar to the "channel mixer" tool in popular photo editing software. |
| 301 | +//| Imagemagick calls this "-color-matrix". In PIL, this is accomplished with the |
| 302 | +//| ``convert`` method's ``matrix`` argument. |
297 | 303 | //| |
298 | 304 | //| The ``bitmap``, which must be in RGB565_SWAPPED format, is modified |
299 | 305 | //| according to the ``weights``. |
300 | 306 | //| |
301 | | -//| If ``weights`` is a list of length 3 (or a `ChannelScale` |
302 | | -//| object), then each channel is scaled independently: The |
| 307 | +//| If ``weights`` is a `ChannelScale` |
| 308 | +//| object, then each channel is scaled independently: The |
303 | 309 | //| numbers are the red, green, and blue channel scales. |
304 | 310 | //| |
305 | | -//| If ``weights`` is a list of length 6 (or a `ChannelScaleOffset` |
306 | | -//| object), then each channel is scaled and offset independently: |
| 311 | +//| If ``weights`` is a `ChannelScaleOffset` |
| 312 | +//| object, then each channel is scaled and offset independently: |
307 | 313 | //| The first two numbers are applied to the red channel: scale and |
308 | 314 | //| offset. The second two number are applied to the green channel, |
309 | 315 | //| and the last two numbers to the blue channel. |
310 | 316 | //| |
311 | | -//| If ``weights`` is a list of length 9 (or a `ChannelMixer` |
312 | | -//| object), then channels are mixed. The first three |
| 317 | +//| If ``weights`` is a `ChannelMixer` |
| 318 | +//| object, then channels are mixed. The first three |
313 | 319 | //| numbers are the fraction of red, green and blue input channels |
314 | 320 | //| mixed into the red output channel. The next 3 numbers are for |
315 | 321 | //| green, and the final 3 are for blue. |
316 | 322 | //| |
317 | | -//| If ``weights`` is a list of length 12 (or a `ChannelMixerOffest` |
318 | | -//| object), then channels are mixed with an offset. |
| 323 | +//| If ``weights`` `ChannelMixerOffset` |
| 324 | +//| object, then channels are mixed with an offset. |
319 | 325 | //| Every fourth value is the offset value. |
320 | 326 | //| |
321 | 327 | //| ``mask`` is another image to use as a pixel level mask for the operation. |
@@ -394,6 +400,20 @@ STATIC mp_obj_t bitmapfilter_mix(size_t n_args, const mp_obj_t *pos_args, mp_map |
394 | 400 | } |
395 | 401 | MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_mix_obj, 0, bitmapfilter_mix); |
396 | 402 |
|
| 403 | +//| def solarize(bitmap, threshold: float = 0.5, mask: displayio.Bitmap | None = None): |
| 404 | +//| """Creat a "solarization" effect on an image |
| 405 | +//| |
| 406 | +//| This filter inverts pixels with brightness values above ``threshold``, while leaving |
| 407 | +//| lower brightness pixels alone. |
| 408 | +//| |
| 409 | +//| This effect is similar to `an effect observed in real life film |
| 410 | +//| <https://en.wikipedia.org/wiki/Solarization_(photography)>`_ which can also be |
| 411 | +//| `produced during the printmaking process |
| 412 | +//| <https://en.wikipedia.org/wiki/Sabattier_effect>`_ |
| 413 | +//| |
| 414 | +//| PIL and ImageMagic both call this "solarize". |
| 415 | +//| """ |
| 416 | +//| |
397 | 417 | STATIC mp_obj_t bitmapfilter_solarize(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
398 | 418 | enum { ARG_bitmap, ARG_threshold, ARG_mask }; |
399 | 419 | static const mp_arg_t allowed_args[] = { |
@@ -438,6 +458,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize); |
438 | 458 | //| This can be used to implement non-linear transformations of color values, |
439 | 459 | //| such as gamma curves. |
440 | 460 | //| |
| 461 | +//| This is similar to, but more limiting than, PIL's "LUT3D" facility. It is not |
| 462 | +//| directly available in OpenMV or ImageMagic. |
| 463 | +//| |
441 | 464 | //| The ``bitmap``, which must be in RGB565_SWAPPED format, is modified |
442 | 465 | //| according to the values of the ``lookup`` function or functions. |
443 | 466 | //| |
@@ -515,6 +538,11 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_lookup_obj, 0, bitmapfilter_lookup); |
515 | 538 | //| ) -> displayio.Bitmap: |
516 | 539 | //| """Convert the image to false color using the given palette |
517 | 540 | //| |
| 541 | +//| In OpenMV this is accomplished via the ``ironbow`` function, which uses a default |
| 542 | +//| palette known as "ironbow". Imagemagic produces a similar effect with ``-clut``. |
| 543 | +//| PIL can accomplish this by converting an image to "L" format, then applying a |
| 544 | +//| palette to convert it into "P" mode. |
| 545 | +//| |
518 | 546 | //| The ``bitmap``, which must be in RGB565_SWAPPED format, is converted into false color. |
519 | 547 | //| |
520 | 548 | //| The ``palette``, which must be of length 256, is used as a look-up table. |
|
0 commit comments