changes the pixel values at pixel position ppos in image to val.


assumes val to be of the specified type.


  • Pixel positions ppos can be in one of the following forms:
  • {x,y}or {x,y,z}single position in 2D or 3D
    {xmin;;xmax,}span of positions
    {ppos1,ppos2,}a list of position specification
    markerimagea marker image
  • In ReplacePixelValue[image,{xp,yp}->val], the pixel position {xp,yp}={x+1/2,y+1/2} with {x,y} assumed to be in the standard image coordinate system, where the values of x range from 0 to width and y from 0 to height.
  • In ReplacePixelValue, integer coordinates correspond to the centers of the pixels. In 2D, pixel position represents the center of the bottom-left pixel. In 3D, pixel position corresponds to the center of the bottom-left front pixel.
  • The pixel value val can be a scalar, a list of channel values, or a color.
  • ReplacePixelValue[image,{ppos1->val1,}] can be used to set pixel values for multiple positions.
  • When the pixel position ppos lies on a boundary between pixels, all adjacent pixels are modified.
  • ReplacePixelValue typically gives an image that has the same type as image.


open all close all

Basic Examples  (3)

Set a pixel in an image:

Click for copyable input

Unset a pixel to separate connected components:

Click for copyable input

Set a pixel in the top-left front corner of a 3D image to gray:

Click for copyable input

Scope  (7)

Possible Issues  (1)

Introduced in 2012
Updated in 2014