Converting a JPG or PNG into digital numbers (DNs)—typically integer values from 0 to 255 representing intensity per channel (RGB or Grayscale)—depends on whether you prefer programmatic scripts, specialized software, or online tools.
1. Python Libraries Best for Automation & Data Export
Python treats images natively as numeric arrays (H × W × C) using 8-bit unsigned integers (uint8).
- NumPy + Pillow/OpenCV: Core stack for array manipulation and image decoding.
- ImageIO / SciPy: Direct reading into NumPy arrays for scientific processing.
from PIL import Image
import numpy as np
# Load image and convert to RGB
img = Image.open("input.jpg").convert("RGB")
pixel_array = np.array(img) # Shape: (Height, Width, 3)
# Access pixel at row Y=10, col X=20 -> returns [R, G, B] values (0-255)
print("RGB at (10,20):", pixel_array[10, 20])
# Export to CSV (flattened or single channel)
np.savetxt("red_channel.csv", pixel_array[:, :, 0], fmt="%d", delimiter=",")
2. Desktop GUI & GIS Tools Best for Visual Inspection
-
ImageJ / Fiji: Free, open-source scientific image processing software.
How to use: Open image →File→Save As→Text Image...(exports a tab-delimited matrix of pixel values) orAnalyze→Tools→Pixel Inspection. -
QGIS / ArcGIS Pro: Ideal if working with spatial data or satellite imagery.
How to use: Load JPG/PNG as a raster layer → use the Identify Features tool to click pixels and view exact Digital Numbers per band, or export raster values via Translate (Convert Format) to ASCII Grid / CSV. -
MATLAB: Command
img = imread('image.jpg');stores the image directly as a 3D numerical matrix.
3. Command-Line Tools
ImageMagick: Convert an image directly into plain text matrix format containing pixel coordinates and RGB/HEX values:
magick convert input.jpg output.txt
Output format: 0,0: (255,128,64) #FF8040 srgb(255,128,64)
4. Web-Based Converters
- PineTools (Image to Array): Converts uploaded images into CSV, JSON, or plain text arrays of RGB values directly in the browser.
-
Image Color Picker: Web tools like
imagecolorpicker.comlet you click any pixel on an uploaded image to inspect its underlying RGB/HEX digital values.

Comments
Post a Comment