Skip to main content
v2026.11,986 entries · CC-BY 4.0

MATLAB image: Display and Read Arrays Guide

Use MATLAB image functions to read, display, and scale 2D and 3D numeric matrices with imread, image, and imagesc for scientific image processing.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

The MATLAB image functions provide a direct interface for importing, displaying, and manipulating multidimensional scientific raster data as numeric matrices. In computational research, experimental data acquired from sensors, microscopes, satellites, and imaging spectroscopy are stored natively as two-dimensional intensity grids or three-dimensional multichannel arrays. By understanding how MATLAB maps matrix values to screen pixels and colormaps, researchers can reliably visualize quantitative datasets, calibrate spatial axes, and export publication-ready figures without visual artifacts.

What it is used for in research

In scientific computing, researchers rarely treat images solely as decorative graphics; instead, an image represents a spatial matrix of measurements. The primary MATLAB image handling commands—image, imagesc, imread, and imwrite—are standard across quantitative disciplines:

  • Digital Microscopy and Bio-Imaging: Quantifying cellular fluorescence intensity, measuring cell morphology, and tracking spatial fluorescence distribution across multichannel optical sections.
  • Remote Sensing and Earth Sciences: Analyzing multispectral satellite imagery, synthetic aperture radar (SAR) amplitude data, and geographic digital elevation models (DEMs).
  • Materials Science and Crystallography: Visualizing scanning electron microscopy (SEM) micrographs, X-ray diffraction patterns, and atomic force microscopy surface roughness topologies.
  • Numerical Modeling and Simulation: Plotting finite-difference spatial grids, heat diffusion heatmaps, fluid velocity vectors, and computational physics field tensors.

Working with image data in MATLAB integrates directly with broader matrix workflows, including MATLAB reshape operations, linear algebra transformations, and specialized signal analysis in MATLAB routines.

How to install or access it

MATLAB is commercial scientific software developed by MathWorks. The core image, imagesc, imread, and imwrite functions are built directly into standard MATLAB installations and do not require additional add-on licenses:

  • Academic and Institutional Access: Most research universities and research institutes provide MATLAB through campus-wide site licenses. Academic researchers can download and activate MATLAB through the official MathWorks Portal using their institutional single sign-on (SSO) credentials.
  • Interactive Web Access: Active license holders can access MATLAB Online directly in modern web browsers without local installation, providing cloud access to storage and compute kernels.
  • Documentation Access: Syntax references and function signatures are accessible within any active MATLAB session via the built-in MATLAB doc command by typing doc image or help imread in the Command Window.
  • Open-Source Compatibility: Researchers working in reproducible open-science environments without active MATLAB commercial licensing can execute identical commands in GNU Octave, which maintains native compatibility with the MATLAB image command suite.

Step-by-step instructions

Follow these numbered steps to load a scientific raster image from disk, inspect its matrix structure, display it with spatial coordinate calibration, and export the processed output.

1. Read the image into the workspace

Import a standard image file (such as a PNG, TIFF, or JPEG) into a workspace variable using the imread function. For scientific analysis, uncompressed formats such as TIFF or lossless PNG are strongly preferred over lossy JPEG files:

% Read scientific image file into numeric array
imgData = imread('sample_microscopy.png');

2. Inspect array dimensions and data type

Examine the array properties to determine whether the image is a 2D intensity grid or a 3D multichannel RGB array:

% Check dimensions and numeric storage class
dims = size(imgData);
dataClass = class(imgData);

% Display summary in Command Window
fprintf('Dimensions: %d x %d with %d channels | Data type: %sn', ...
    dims(1), dims(2), size(imgData, 3), dataClass);

Grayscale and binary images load as $M imes N$ matrices, while standard color images load as $M imes N imes 3$ matrices, typically stored as uint8 (values 0 to 255) or uint16 (values 0 to 65535).

3. Display the image array

Render the matrix in a MATLAB figures window using either image or imagesc depending on your data scaling requirements:

% Open a new figure window
figure('Name', 'Scientific Image Visualization');

% Option A: Direct colormap mapping using image()
% Suitable when matrix values directly correspond to indexed colormap rows
hImg = image(imgData);

% Option B: Scaled intensity mapping using imagesc()
% Automatically normalizes matrix minimum and maximum across current colormap
% imagesc(imgData, [0 255]);

4. Calibrate physical spatial axes and proportions

By default, MATLAB places pixel coordinate $(1,1)$ at the top-left corner and may distort the aspect ratio to fill the figure window. Use axes configuration commands to enforce true physical scaling:

% Lock aspect ratio so pixels remain square (1:1 aspect ratio)
axis image;

% Add a calibrated color bar indicating intensity levels
colorbar;
title('Calibrated Specimen Intensity');
xlabel('Horizontal Pixel Coordinate');
ylabel('Vertical Pixel Coordinate');

If your dataset corresponds to Cartesian coordinates where the vertical origin should start at the bottom-left, apply axis xy to invert the vertical axis.

5. Process and export the modified matrix

After performing matrix calculations (such as contrast normalization, filtering, or cropping), save the resulting array back to disk using imwrite:

% Example: Invert contrast for high-contrast presentation
processedData = 255 - imgData;

% Write processed array to a 16-bit PNG file
imwrite(processedData, 'processed_output.png');

Output and how to read it

Executing the image or imagesc command generates a graphical figure window containing an Image object child within an Axes object. Interpreting this output accurately requires understanding three core elements:

  • Pixel Coordinate System: The horizontal axis ($X$) represents matrix column indices ranging from $1$ to $N$, while the vertical axis ($Y$) represents matrix row indices ranging from $1$ to $M$. Pixel centers are located at integer coordinates $(x, y)$.
  • Color Mapping Behavior:
    • For RGB arrays ($M imes N imes 3$), values in the third dimension define the red, green, and blue intensities directly. MATLAB ignores the active figure colormap and displays true color.
    • For 2D arrays ($M imes N$), image(C) treats each matrix element as an index into the current figure colormap (direct mapping). If matrix values exceed the length of the colormap, they are clipped to the maximum colormap color.
    • In contrast, imagesc(C) performs linear scaling: the minimum value maps to the first color, and the maximum value maps to the last color, ensuring full dynamic range visualization.
  • Data Cursor Inspection: Researchers can enable the interactive Data Tips tool from the figure toolbar to inspect the exact $(X, Y)$ coordinate and underlying numeric value of individual pixels.

Troubleshooting

When visualizing scientific matrices in MATLAB, researchers commonly encounter several recurring issues. Use these verified diagnostic solutions:

  • Image Appears Completely Black or Blank:

    Cause: The matrix data type is double with values in the range 0 to 255, but MATLAB interprets double images in standard display pipelines as ranging from 0.0 (black) to 1.0 (white). Any value greater than or equal to 1.0 is rendered as pure white, or non-scaled integer arrays may fall outside small colormaps.

    Fix: Use imagesc(C) instead of image(C) to automatically scale the intensity range, or normalize your array using C_norm = mat2gray(C); or im2double(C);.

  • Pixels Are Stretched or Distorted:

    Cause: The default MATLAB axes mode stretches graphics to fill the rectangular aspect ratio of the figure window.

    Fix: Execute axis image immediately after calling image. This locks the plot box aspect ratio to match the matrix dimensions.

  • Image Is Flipped Upside Down:

    Cause: Image processing conventions index the origin $(1,1)$ at the top-left corner (matrix notation, axis ij), whereas Cartesian scientific plots place $(0,0)$ at the bottom-left corner.

    Fix: Call axis xy to switch to Cartesian orientation, or axis ij to restore standard image matrix orientation.

  • Unsupported Image File Formats or Multi-Frame Errors:

    Cause: Attempting to read multi-page scientific TIFF stacks with a single imread(filename) call loads only the first frame.

    Fix: Pass the frame index explicitly: frame2 = imread('stack.tif', 2);, or query metadata first using imfinfo('stack.tif').

Free alternatives

Researchers seeking reproducible, open-source computing alternatives to proprietary MATLAB workflows can utilize several mature software packages. When selecting between environments, evaluate syntax compatibility and ecosystem requirements as detailed in our MATLAB vs R comparison and general open-source software tools guide.

Software Environment Primary Research Use Case Syntax / Equivalent Functions License Model
GNU Octave Direct numerical drop-in replacement for MATLAB m-files and matrix analysis. image(img), imagesc(img), imread(), imwrite() GNU GPLv3 (Free Software)
Python (Matplotlib & NumPy) General scientific computing, statistical modeling, and publication plotting. plt.imshow(array, cmap='viridis'), plt.imsave() BSD / PSF Compatible
Python (scikit-image) Advanced bioimage analysis, morphological filtering, and segmentation. skimage.io.imread(), skimage.io.imshow() Modified BSD (3-Clause)
ImageJ / Fiji Cellular microscopy, particle counting, and interactive bio-image stacks. Interactive GUI menus or ImageJ Macro / Jython API Public Domain / BSD / GPL

FAQ

What is the difference between image, imagesc, and imshow in MATLAB?

The image function displays a matrix using direct colormap indexing without rescaling numeric values. The imagesc function automatically normalizes matrix values so that the minimum and maximum data points span the entire active colormap. The imshow function is a specialized viewer that configures axes limits, removes tick marks, and optimizes aspect ratios specifically for photographic and scientific images.

How do I display a matrix with physical coordinate units in MATLAB?

Pass spatial coordinate vectors to the image function: image(x, y, C), where x = [xMin, xMax] and y = [yMin, yMax] represent the physical bounds (such as millimeters or microns). The axes will display real-world dimensions rather than discrete pixel indices.

Why does my double-precision image appear completely white?

MATLAB expects double arrays to have values between 0.0 and 1.0 when rendered with standard image commands. If your array contains raw sensor values ranging from 0 to 255 or higher, convert it using im2double() or visualize it using imagesc(C) to scale the display range automatically.

Can I run MATLAB image scripts in GNU Octave without modification?

Yes. GNU Octave provides native implementations of image, imagesc, imread, and imwrite that follow identical function signatures, coordinate conventions, and return structures for scientific matrix computing.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about MATLAB image: Display and Read Arrays Guide

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →