matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-modernize-code
matlab-modernize-code
VerifiedModernize removed or discouraged MATLAB functions and patterns. Use when the check_matlab_code MCP tool reports that a function "is not recommended", "will be removed in a future release", or "has been removed" — at any severity (info, warning, or error) — when migrating legacy code, or when replacing removed or discouraged APIs with current equivalents. Also applies to discouraged patterns Code Analyzer does not flag (containers.Map, bsxfun, str2num, eval, clear all) and to removed or discouraged functions such as trainNetwork, csvread, xlsread, datenum, guide, svmtrain, ltln2val, webmap.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.7 KB |
| manifest.yaml | config | 1.1 KB |
| references/audio-video-guidance.md | markdown | 9.4 KB |
| references/communications-guidance.md | markdown | 8.5 KB |
| references/control-systems-guidance.md | markdown | 5.0 KB |
| references/core-functions-guidance.md | markdown | 22.1 KB |
| references/deep-learning-guidance.md | markdown | 3.3 KB |
| references/image-processing-guidance.md | markdown | 6.9 KB |
| references/mapping-guidance.md | markdown | 14.5 KB |
| references/optimization-guidance.md | markdown | 6.0 KB |
| references/signal-processing-guidance.md | markdown | 5.0 KB |
| references/statistics-ml-guidance.md | markdown | 8.0 KB |
references/image-processing-guidance.md
View on GitHub# Image Processing Modernization
## Quick Reference: Function Mappings
| Topic | Recommendation | Since | Status |
|---|---|---|---|
| `impoly` | `drawpolygon` / `images.roi.Polygon` | R2018b | Not Recommended |
| `imellipse` | `drawellipse` / `images.roi.Ellipse` | R2018b | Not Recommended |
| `imfreehand` | `drawfreehand` / `images.roi.Freehand` | R2018b | Not Recommended |
| `imrect` | `drawrectangle` / `images.roi.Rectangle` | R2018b | Not Recommended |
| `impoint` | `drawpoint` / `images.roi.Point` | R2018b | Not Recommended |
| `imline` | `drawline` / `images.roi.Line` | R2018b | Not Recommended |
| `roifill` | `regionfill` | R2019a | Not Recommended |
## ROI (Region of Interest) Tools
### Overview of ROI Modernization
Starting in **R2018b**, a new set of ROI objects replaced the existing ROI functions. The new objects provide:
- Face color transparency
- Event-based callbacks for ROI changes
- More consistent API across ROI types
- Better performance
**Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities.**
---
### impoly → drawpolygon
**Status:** Not recommended. Use `drawpolygon` or `images.roi.Polygon`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy interactive polygon
imshow(img);
h = impoly(gca);
mask = createMask(h);
pos = getPosition(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern interactive polygon
imshow(img);
roi = drawpolygon;
mask = createMask(roi);
pos = roi.Position;
% Programmatic creation
roi = images.roi.Polygon(gca, Position=[x1 y1; x2 y2; x3 y3]);
% With customization
roi = drawpolygon(Color="red", LineWidth=2, FaceAlpha=0.3);
```
**Event Handling (New Feature):**
```matlab
roi = drawpolygon;
addlistener(roi, 'MovingROI', @(src,evt) disp('Moving!'));
addlistener(roi, 'ROIMoved', @(src,evt) updateAnalysis(src));
```
---
### imellipse → drawellipse
**Status:** Not recommended. Use `drawellipse` or `images.roi.Ellipse`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy ellipse
imshow(img);
h = imellipse(gca, [x y width height]);
mask = createMask(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern interactive ellipse
imshow(img);
roi = drawellipse;
mask = createMask(roi);
% Programmatic creation
roi = images.roi.Ellipse(gca, Center=[100 100], SemiAxes=[50 30]);
% With rotation
roi = drawellipse(Center=[100 100], SemiAxes=[50 30], RotationAngle=45);
```
**For Circular ROIs:**
```matlab
% Use Circle ROI instead of Ellipse for circles
roi = drawcircle(Center=[100 100], Radius=50);
roi = images.roi.Circle(gca, Center=[100 100], Radius=50);
```
---
### imfreehand → drawfreehand
**Status:** Not recommended. Use `drawfreehand` or `images.roi.Freehand`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy freehand
imshow(img);
h = imfreehand(gca);
mask = createMask(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern freehand drawing
imshow(img);
roi = drawfreehand;
mask = createMask(roi);
% With smoothing
roi = drawfreehand(Smoothing=1); % 0-1 smoothing factor
% Assisted freehand (follows edges)
roi = drawassisted; % Snaps to image edges
```
---
### imrect → drawrectangle
**Status:** Not recommended. Use `drawrectangle` or `images.roi.Rectangle`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy rectangle
imshow(img);
h = imrect(gca, [x y width height]);
pos = getPosition(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern interactive rectangle
imshow(img);
roi = drawrectangle;
pos = roi.Position; % [x y width height]
% Programmatic creation
roi = images.roi.Rectangle(gca, Position=[50 50 100 80]);
% With aspect ratio constraint
roi = drawrectangle(FixedAspectRatio=true, AspectRatio=16/9);
```
---
### impoint → drawpoint
**Status:** Not recommended. Use `drawpoint` or `images.roi.Point`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy point
imshow(img);
h = impoint(gca, x, y);
pos = getPosition(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern interactive point
imshow(img);
roi = drawpoint;
pos = roi.Position; % [x y]
% Programmatic creation
roi = images.roi.Point(gca, Position=[100 100]);
% Multiple points
roi = gobjects(1, 5);
for i = 1:5
roi(i) = drawpoint;
end
positions = vertcat(roi.Position);
```
---
### imline → drawline
**Status:** Not recommended. Use `drawline` or `images.roi.Line`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy line
imshow(img);
h = imline(gca, [x1 x2], [y1 y2]);
pos = getPosition(h);
```
**Modern Pattern (Use This):**
```matlab
% Modern interactive line
imshow(img);
roi = drawline;
pos = roi.Position; % [x1 y1; x2 y2]
% Programmatic creation
roi = images.roi.Line(gca, Position=[10 10; 100 100]);
% Polyline (multiple segments)
roi = drawpolyline;
```
---
### roifill → regionfill
**Status:** Not recommended. Use `regionfill`.
**Old Pattern (Not Recommended):**
```matlab
% Legacy ROI fill
mask = roipoly(img); % Interactive polygon selection
filled = roifill(img, mask);
```
**Modern Pattern (Use This):**
```matlab
% Modern region fill with drawpolygon
imshow(img);
roi = drawpolygon;
mask = createMask(roi);
filled = regionfill(img, mask);
% Or programmatically
mask = poly2mask(x, y, size(img,1), size(img,2));
filled = regionfill(img, mask);
```
---
## Complete ROI Migration Table
| Old Function | New Object | Convenience Function |
|--------------|------------|---------------------|
| impoly | images.roi.Polygon | drawpolygon |
| imellipse | images.roi.Ellipse | drawellipse |
| imfreehand | images.roi.Freehand | drawfreehand |
| imrect | images.roi.Rectangle | drawrectangle |
| impoint | images.roi.Point | drawpoint |
| imline | images.roi.Line | drawline |
| - | images.roi.Circle | drawcircle |
| - | images.roi.Polyline | drawpolyline |
| - | images.roi.AssistedFreehand | drawassisted |
| - | images.roi.Cuboid | drawcuboid |
| - | images.roi.Crosshair | drawcrosshair |
---
## Property Name Changes
| Old Method | New Property |
|------------|--------------|
| getPosition | Position |
| setPosition | Position |
| getColor | Color |
| setColor | Color |
| getVertices | (use Position) |
| addNewPositionCallback | MovingROI event |
---
## Working with Multiple ROIs
**Modern Pattern:**
```matlab
% Draw multiple ROIs
imshow(img);
rois = gobjects(1, 3);
for i = 1:3
rois(i) = drawrectangle;
end
% Get all masks
combinedMask = false(size(img, 1), size(img, 2));
for i = 1:length(rois)
combinedMask = combinedMask | createMask(rois(i));
end
% Delete all ROIs
delete(rois);
```
---
## ROI Events (New Feature)
**The new ROI objects support events:**
```matlab
roi = drawrectangle;
% Listen for movement
addlistener(roi, 'MovingROI', @(src,evt) disp('Moving...'));
addlistener(roi, 'ROIMoved', @(src,evt) disp('Done moving'));
% Listen for clicks
addlistener(roi, 'ROIClicked', @handleClick);
function handleClick(src, evt)
if strcmp(evt.SelectionType, 'double')
disp('Double-clicked!');
end
end
```
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |