Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pygmt/src/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

@fmt_docstring
@use_alias(D="position", G="bitcolor")
def image(
def image( # noqa: PLR0913
self,
imagefile: PathLike,
projection: str | None = None,
region: Sequence[float | str] | str | None = None,
box: Box | bool = False,
monochrome: bool = False,
invert: bool = False,
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
| bool = False,
panel: int | Sequence[int] | bool = False,
Expand Down Expand Up @@ -48,6 +49,7 @@ def image(

$aliases
- F = box
- I = invert
- J = projection
- M = monochrome
- R = region
Expand Down Expand Up @@ -85,6 +87,13 @@ def image(
monochrome
Convert color image to monochrome grayshades using the (television)
YIQ-transformation.
invert
Invert 1-bit image before plotting, i.e., black pixels (on) becomes white (off)
and vice versa. Ignored if used with color images.
Comment on lines +90 to +92
Copy link
Member

@yvonnefroehlich yvonnefroehlich Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, just trying this and maybe I am missing something here. I thought the remote raster image "vader1.png" is such a 1-bit image (see the last example at https://docs.generic-mapping-tools.org/dev/image.html#examples), but using I=True does not flip the black and white pixels as expected:

import pygmt

fig = pygmt.Figure()
fig.basemap(region=[-5, 5] * 2, projection="X3c/1c", frame=0)

fig.image(imagefile="@vader1.png", position="jLM")
fig.image(imagefile="@vader1.png", position="jMC", bitcolor=["gray+f", "blue+b"])
fig.image(imagefile="@vader1.png", position="jRM", I=True)  # Does not do something
# fig.image(imagefile="@vader1.png", position="jRM", bitcolor=["black+f", "white+b"])

fig.show()
image_invert

Same for

gmt image @vader1.png -I -png image_I_gmt
image_I_gmt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it looks like an upstream bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with the gmt dev version, and still no inverted colors. Thus, I wrote an issue report at GenericMappingTools/gmt#8795.

Copy link
Member Author

@seisman seisman Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upstream bug has been fixed.

I've added a note in the docstrings.


**Note**: There was an upstream GMT bug, so this feature may not work correctly
for some 1-bit images for GMT<=6.6.0.
See `PR #8837 <https://github.com/GenericMappingTools/gmt/pull/8837>`__.
$verbose
$panel
$perspective
Expand All @@ -95,6 +104,7 @@ def image(
aliasdict = AliasSystem(
F=Alias(box, name="box"),
M=Alias(monochrome, name="monochrome"),
I=Alias(invert, name="invert"),
).add_common(
J=projection,
R=region,
Expand Down