ReplacePixelValue[image,pposval]
changes the pixel values at pixel position ppos in image to val.
ReplacePixelValue[image,pposval,"type"]
assumes val to be of the specified type.
ReplacePixelValue
ReplacePixelValue[image,pposval]
changes the pixel values at pixel position ppos in image to val.
ReplacePixelValue[image,pposval,"type"]
assumes val to be of the specified type.
Details
- ReplacePixelValue is typically used for image correction or annotation of 2D and 3D images by replacing pixel values at selected positions.
- ReplacePixelValue assumes a pixel-aligned coordinate system that is shifted by 0.5 to the left and down with respect to the standard image coordinate system.
- 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. - 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 {xmin;;xmax;;xstep,…} span of positions with steps {pos1,pos2,…} a list of position specifications markerimage a marker image - 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.
- Pixel value val can be in one of the following forms:
-
s a scalar color a color {s1,s2,…} a list of channel values - Possible settings for "type" include:
-
"Bit" integer 0 or 1 "Byte" integer 0 through 255 "Bit16" integer 0 through 65535 "Real32" single-precision real (32 bit) "Real64" double-precision real (64 bit) - ReplacePixelValue typically gives an image that has the same type as image.
Examples
open all close allBasic Examples (3)
ReplacePixelValue[[image], {2, 2} -> 1]Replace a list of pixels in an image:
ReplacePixelValue[[image], Table[{i, i} -> Hue[(i - 1) / 5] , {i, 6}]]Specify the data type of the replacement value:
ReplacePixelValue[[image], {2, 2} -> 255, "Byte"]Scope (12)
Data (4)
Replace a value in a grayscale image:
ReplacePixelValue[[image], {2, 1} -> 1]Replace a value in a color image:
ReplacePixelValue[[image], {1, 1} -> Yellow]Replace a value in a grayscale 3D image:
ReplacePixelValue[[image], {3, 1, 3} -> 0]Set a pixel in the top-left front corner of a 3D color image to gray:
ReplacePixelValue[[image], {1, 1, 3} -> Gray]Position (6)
ReplacePixelValue[[image], {1, 1} -> Cyan]Replace pixel values at multiple positions:
ReplacePixelValue[[image], {{1, 1} -> Cyan, {2, 1} -> Yellow}]Replace multiple pixel values:
ReplacePixelValue[[image], {{1, 1}, {2, 1}} -> Cyan]Use Span to replace multiple pixel values:
ReplacePixelValue[[image], {1 ;; 2, 1} -> Cyan]ReplacePixelValue[[image], {All, 3} -> Red]Use a marker image to replace pixel values:
ReplacePixelValue[[image], [image] -> Red]Applications (2)
Replace black beans with red beans:
ppos = PixelValuePositions[[image], RGBColor[{0.20392145216464996, 0.09019557386636734, 0.18039168417453766}], 0.16];ReplacePixelValue[[image], ppos -> RGBColor[{0.8156862745098039, 0.16862745098039217, 0.15294117647058825}]]Extract pixel coordinates of handwritten annotations in a document:
img = [image];
pos = PixelValuePositions[img, Red, 0.35];mask = ReplaceImageValue[ConstantImage[Black, ImageDimensions[img]], pos -> White]ReplacePixelValue[img, Dilation[mask, 1] -> White]Properties & Relations (3)
Any position within the bounds of a pixel may be used:
ReplacePixelValue[[image], {3.35, 3.35} -> Red]When the specified coordinate falls between pixels, all surrounding pixels are modified:
ReplacePixelValue[[image], {2.5, 2.5} -> Red]If a position outside of the image bounds is specified, no pixel is modified:
ReplacePixelValue[[image], {{0.35, 0.35}, {3.65, 3.65}} -> Red]Related Guides
Text
Wolfram Research (2012), ReplacePixelValue, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplacePixelValue.html (updated 2014).
CMS
Wolfram Language. 2012. "ReplacePixelValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/ReplacePixelValue.html.
APA
Wolfram Language. (2012). ReplacePixelValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplacePixelValue.html
BibTeX
@misc{reference.wolfram_2026_replacepixelvalue, author="Wolfram Research", title="{ReplacePixelValue}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ReplacePixelValue.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_replacepixelvalue, organization={Wolfram Research}, title={ReplacePixelValue}, year={2014}, url={https://reference.wolfram.com/language/ref/ReplacePixelValue.html}, note=[Accessed: 13-June-2026]}