IMVIEW: A New Image Display Function
I've been working on a new image display function that I intend to use instead of imshow.
After 31 years of developing, using, and too-often struggling with imshow
, it is time for me to move on. I've been working on a new image display function, called imview
, that I intend to use instead of imshow
for my own work. I have submitted an initial version of imview
to the File Exchange.
I sometimes joke that I spent my MathWorks career revisiting the same three topics over and over: convolution, image resizing, and imshow
. In fact, my familiarity with imshow
predates my time at MathWorks. In the summer of 1993, I was a beta tester of the first version of the Image Processing Toolbox, and much of my product feedback was about imshow
.
The imshow
implementation has transformed several times since its creation, to evolve along with changes in MATLAB graphics and language. The current implementation has a huge amount of code that copes with its nonstandard behavior and many, many challenging edge cases. Most of the complexity is related to a decision in 1997 to make imshow
automatically resize the figure based on the size (in pixels) of the image. At the time, this decision was necessary to achieve a reasonable quality image display based on computer monitor resolution and MATLAB graphic capabilities at the time. (I'm thinking of writing another blog post to elaborate on this history.) But this figure size manipulation has been the source of a bunch of glitchy behavior and ad hoc work-arounds. For example, there is code in imshow
that checks for the existence of user interface controls, as well as the NextPlot
state of the axes, to determine (imperfectly) whether it is "safe" to try to resize the figure.
Another imshow
issue is that the default image interpolation method is nearest-neighbor, and there is no antialiasing applied when the image is shrunk for display. (This is not 100% accurate, as the MATLAB graphics rendering pipeline always applies a relatively simple smoothing step.) In the 1990s, nearest-neighbor image display was the only method available in MATLAB, but that is not the case today. Bilinear interpolation with antialiasing was added as an option to the image
object sometime around 2017. Because of compatibility considerations, though, nearest neighbor remained the default for both the image
object and for imshow
.
A third issue concerns setting the x- and y-axis limits. From the beginning, imshow
manually set the axes limits (via the XLim
and YLim
properties) to cover the exact extent of image pixels, instead of the normal MATLAB graphics behavior of including extra horizontal and vertical space as needed to make the end tick labels be nice round numbers. This was also partially related to typical 1990s computer monitor resolutions, as every "wasted" screen pixel was a problem when displaying images.
A side effect of setting the XLim
and YLim
properties is that these limits become fixed and no longer update automatically when additional data is plotted into the same axes. In MATLAB today, there is a different way to achieve tight limits without freezing them: set the XLimitMethod
and YLimitMethod
properties to "tight"
.
In summary, imshow
has a huge amount of glitchy and hard-to-maintain code that implements default behaviors that made sense 25 years ago, but not today. That is why, in the last year of my MathWorks career, I advocated to anyone who would listen that it was time to move on from imshow
and make something that works better for the MATLAB and the computers of the 2020s.
The Image Processing Toolbox team has done that with the new function imageshow
, introduced in R2024b. This function creates a kind of image viewer that is designed for high-performance visualization of very large images, even when then they don't fit entirely within memory. The display created by imageshow
, however, is in a custom-purpose window, rather than living in an ordinary axes
in an ordinary figure
.
I believe there is a need for an imshow
replacement that creates an image
object that lives in an axes
, so that it can interact with other MATLAB graphics objects and capabilities, just as imshow
does. My attempt to do that is my function imview
.
Comparing IMVIEW and IMSHOW
Here are the specific differences between imview
and imshow
:
imview
does not resize the figure containing the image display. Instead, the image is displayed in the current axes in the current figure without changing the figure or axes size.imview
displays the image using bilinear interpolation and antialiasing, unless individual pixels are larger than about 0.2 inches. In that case, the interpolation switches automatically to nearest neighbor, and a pixel grid is shown. The functionimshow
uses nearest neighbor interpolation by default.- Unlike
imshow
,imview
does not explicitly set the axesXLim
andYLim
properties. Instead, it sets theXLimitMethod
andYLimitMethod
properties to"tight"
. With this choice, the axes limits will tightly enclose the data contained by the axes, including the image and anything else that might also be plotted in the same axes. Also unlikeimshow
, the axes limits will continue to automatically adjust to additional data being plotted there. imview
does not observe the MATLAB Image Display Preferences.
Limitations
The function imview
is under development. There is a lot left to do. This version does not yet have some of the options supported by imshow, including:
- Overriding the default black-white range
- Overriding the default interpolation behavior
- Overriding the default XData and YData
- Setting the initial magnification level
- Specifying the parent axes
- Displaying an indexed image
- Using an image filename or URL
The optional imshow
behavior that I use most frequently is overriding the default black-white range, so that is probably what I will work on next.
Your Feedback
If you try imview
(get it from the File Exchange, I would be interested in your feedback. There are several ways that you can provide feedback, including:
- Click "Contact" on this blog.
- Start a discussion or add a review directly on the File Exchange page.
- Create an issue on the GitHub repository.
Installation Note
There is a stub function in Image Processing Toolbox that is also called imview
. This was an image display function that was in the product about 20 years ago. That capability was removed, and that stub function only errors now. You may need to manually modify that MATLAB search path that the folder containing the new imview
is at or near the top, ahead of the Image Processing Toolbox path folders.
I will be creating a MathWorks support request to ask the Image Processing Toolbox team to remove this old stub function.