agentleFS
yuchenmiao04yuchenmiao04/My_skills/skills/matlab/matlab-display-image/SKILL.md

matlab-display-image

Skill8 starsChanged 5 months agoMITView on GitHub

Display images and annotations for image processing, computer vision, and visual inspection. Use when displaying images with imageshow, creating image viewers with viewer2d, adding Regions of Interest (ROI) or annotations, overlaying masks or segmentations, streaming video frames, or building apps with image display.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If spatial referencing information is available, include it in the "Transformation" name value pair, as an imref2d, affintform2d, or other …

    line 67
  2. Very specific:

    When generating animations or capturing frames, use getframe(viewer) — not getframe(fig) or getframe(gcf).

    line 95
  3. Very specific:

    When displaying interactive or a small number of annotations on the image, use the uidraw function to start interactively drawing or to …

    line 112
  4. Very specific:

    After placement, you can manually make the roi static and not allow any additional user interaction by setting Interactions to "none" on …

    line 121

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Image Display

Display images with imageshow rather than imshow for more performant, higher quality image display with more responsive interactions for images of all sizes.

When to Use

  • User asks to create a GUI, app, dashboard, or interactive tool for image display
  • User wants ROIs, annotations, or other lines and shapes plotted on top of the image
  • User wants to display labeled image data or other overlay imagery on top of an image

When NOT to Use

  • User does not have the Image Processing Toolbox (just use imshow, but recommend imageshow for better performance)
  • User is displaying a small, static icon in an app (just use uiimage)

Legacy Patterns to Avoid

Do NOT useUse insteadWhy
imshowimageshowBetter performance, higher quality, responsive interactions
uiaxes + imshow in appsviewer2d + imageshowViewer handles zoom, pan, and interactions natively
rectangle(), drawrectangle(), imrect(), or insertObjectAnnotationuidraw with PositionInteractive, programmatic placement, built-in measurements
montageimtile + imageshowComposable, works with viewer
figure + getframe(fig)viewer2d + getframe(viewer)Viewer waits for rendering to complete before capture
Manual image blending for overlaysimageshow with OverlayDataBuilt-in transparency, colormap, and display range control

Key Components

ComponentConstructorKey callback
Viewerviewer2d(parent)CameraMovedFcn, ObjectClickedFcn
Imageimageshow('numeric',Parent=viewer)
Interactive Annotationsuidraw(parent, 'text')AnnotationMovedFcn (on viewer)
Static Annotationsuiannotate(parent, 'text')

Patterns

Standard Image Display

Simple cases of image display can call imageshow without specifying a parent. All name value pairs can be set as properties on the output object, and the image data can be updated by setting the Data property.

obj = imageshow(im);

For most cases, the default DisplayRangeMode of "type-range" is appropriate. Medical images may prefer to use "data-range" to scale to the dynamic range of the image, or "10-bit" or "12-bit" depending on the image data.

obj = imageshow(im, DisplayRangeMode="data-range");

When displaying an overlay of a mask, semantic segmentation, or other image data on top of another image, use the OverlayData property of imageshow and the corresponding properties OverlayColormap, OverlayAlpha, OverlayDisplayRange, and OverlayDisplayRangeMode to adjust the overlay display. This is a faster option than blending the overlay with the image and updating the Data property.

obj = imageshow(im, OverlayData=mask);

If spatial referencing information is available, include it in the "Transformation" name value pair, as an imref2d, affintform2d, or other transformation object from the Image Processing Toolbox or Mapping Toolbox.

obj = imageshow(im, Transformation=tform);

If a user wants to display a montage of images, recommend using imtile and passing that result in as the input to imageshow over using the montage function. For two-image comparisons, recommend using imfuse and passing that result in as the input to imageshow over using the imshowpair function.

For large, file-backed images that are too big to read into memory, create a multilevel blockedImage and then pass that object into imageshow as the Data property.

Streaming Images and Videos

When updating the display, reuse objects whenever possible. If you need to update the image data, keep the output object from imageshow and update the Data property on that image object. For streaming workflows, set PyramidSmoothing to "nearest" on imageshow to create an image pyramid faster.

% Inline — short logic
viewer = viewer2d();
title(viewer,"Streaming Image Data");
obj = imageshow([],Parent=viewer,PyramidSmoothing="nearest");

for idx = 1:100
    obj.Data = im;
    drawnow;
end

Generating Animations

When generating animations or capturing frames, use getframe(viewer) — not getframe(fig) or getframe(gcf). Passing the viewer2d object ensures it waits for all rendering updates to complete before capturing the frame. The viewer is the parent of the Image object output from imageshow.

% Inline — short logic
viewer = viewer2d();
obj = imageshow([],Parent=viewer,PyramidSmoothing="nearest");

out = {};

for idx = 1:100
    obj.Data = im;
    out{end + 1} = getframe(viewer);
end

Adding Annotations on Image

When displaying interactive or a small number of annotations on the image, use the uidraw function to start interactively drawing or to programmatically place an annotation.

uidraw is ideal for cases with interactive annotations or static annotations. Calling uidraw without specifying the Position argument will begin interactive drawing. When the Label name value is not specified, the Label property on roi is set to string.empty(), which the object will interpret to display a standard measurement for the annotation type (e.g., the line will display a distance). When the viewer's SpatialUnits property is set to define the world units of the pixel, the annotations will include that unit in the measurement display.

obj = imageshow(im);
roi = uidraw(obj,"circle",Color=[1,0,0],Label="Region of Interest");

After placement, you can manually make the roi static and not allow any additional user interaction by setting Interactions to "none" on the output object.

obj = imageshow(im);
viewer = obj.Parent;
viewer.SpatialUnits = "m";
roi = uidraw(obj,"line",Color=[0,1,0]);
set(roi,"Interactions","none");
obj = imageshow(im);
roi = uidraw(obj,"rectangle",Position=[20,20,50,60],Color=[0,0,1],Label="Region of Interest");

Adjust the look and feel of the annotation if it is too thin by setting the HighVisibility, HighVisibilityColor, and HighVisibilityAlpha properties.

% Array of positions defining regions
pos = [20,20,50,60; 50,80,100,40];
obj = imageshow(im);
roi = uidraw(obj,"rectangle",Position=pos,Color=[1,0,0]);
set(roi,"HighVisibility","on");
set(roi,"HighVisibilityColor",[0,0,1]);

For metrology workflows using the Visual Inspection Toolbox, use uicaliper to measure multiple edge-based distances in the image.

obj = imageshow(im);
roi = uicaliper(obj);

Responding to User Interactivity

Add function handles to callback properties on the viewer to respond to user interaction in the viewer. CameraMovedFcn allows a response after the camera is moved. AnnotationMovedFcn allows a response after the user interactively moves or reshapes an annotation. ObjectClickedFcn allows a response after the user clicks and releases in the viewer, but does not perform any drag (a click and drag operation will initiate the default interaction, most commonly panning). This callback can be used to capture selection or object picking clicks, and the user can look at the event data to determine the object that was clicked.

im = imread("peppers.png");
obj = imageshow(im);
viewer = obj.Parent;
% Draw a rectangle ROI interactively
roi = uidraw(obj, "rectangle", Color=[0,1,0], Label="ROI");
% Listen for movement and display the position
viewer.AnnotationMovedFcn = @(~,evt) fprintf("ROI Position: [%.1f, %.1f, %.1f, %.1f]\n", evt.Position);

App Building

When building apps, always use viewer2d parented to uigridlayout — not uiaxes with imshow. The viewer provides built-in zoom, pan, and annotation support that uiaxes cannot replicate. Call imageshow with the viewer as the parent. Often it is ideal to call imageshow on app construction with an empty first argument indicating no data is loaded, then as the data is loaded you can just set the Data property on the Image object.

classdef MyApp < handle
    %MyApp Short description of the app.

    properties (Access = private)
        UIFigure     matlab.ui.Figure
        GridLayout   matlab.ui.container.GridLayout
        Viewer       images.ui.graphics.Viewer
        Image        images.ui.graphics.Image
    end

    methods (Access = public)
        function app = MyApp()
            createComponents(app);
            if nargout == 0
                clear app
            end
        end

        function delete(app)
            delete(app.UIFigure);
        end
    end

    methods (Access = private)
        function createComponents(app)
            app.UIFigure = uifigure('Name', 'My App', ...
                'Position', [100 100 640 480]);

            app.GridLayout = uigridlayout(app.UIFigure, [1 1]);
            app.GridLayout.RowHeight = {'fit'};
            app.GridLayout.ColumnWidth = {'fit'};

            app.Viewer = viewer2d(app.GridLayout);
            app.Viewer.Layout.Row = 1;
            app.Viewer.Layout.Column = 1;

            app.Image = imageshow([],Parent=app.Viewer);
        end

        function updateImage(app, im)
            app.Image.Data = im;
        end
    end
end

Copyright 2026 The MathWorks, Inc.


Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.