Image processing

(c) Khashin S.I. http://math.ivanovo.ac.ru/dalgebra/Khashin/index.html

khash2 (at) gmail.com

From picture to text and back
Color conversions
Gluing two files
PSNR, MSE
Smoothing and Morphology
Shifts and rotations
Resize
    Various methods of the image doubling
Sprites
Create/fill picture with given colors, stripes and squares
The Fourier Coefficients
Gradients, derivatives, and variation
Show points from two columns of a real matrix in a bmp-file
Conversion to b/w
Cellular automaton
Palitra


From picture to text and back


Cut out the rectangle:
grUtil.exe block src_picture x0 y0 dx dy dst_picture
From picture to 3 text file-matrices:
grUtil.exe toTxt3 src_picture dst_red.txt dst_green.txt dst_blue.txt
From the picture block to three text file-matrix:
grUtil.exe toTxt3b src_picture dst_red.txt dst_green.txt dst_blue.txt x0 y0 dx dy
From 3 text file-matrices to bmp:
grUtil.exe Txt3bmp red.txt green.txt blue.txt picture.bmp
The RGB-color of the pixel -> stdio:
grUtil.exe PColor src_picture x y
The R-color of the pixel -> stdio:
grUtil.exe PColorR src_picture x y
The G-color of the pixel -> stdio:
grUtil.exe PColorG src_picture x y
The B-color of the pixel -> stdio:
grUtil.exe PColorB src_picture x y
The YUV-color of the pixel -> stdio:
grUtil.exe PColorYUV src_picture x y
The Y-color of the pixel -> stdio:
grUtil.exe PColorY src_picture x y
Min/max RGB-color values -> stdio:
grUtil.exe min src_picture
grUtil.exe max src_picture
Min/max RGB-color values on the box -> stdio:
grUtil.exe min x0 y0 dx dy src_picture
grUtil.exe max x0 y0 dx dy src_picture
Histogram for 3 colors:
grUtil.exe histogram src_picture hist.txt


Color conversions

Gray picture
grUtil.exe ToGray src_picture gray_picture
3 colors in separate bmp:
grUtil.exe 3Colors src_picture picture_R  picture_G  picture_B
3 colors in separate gray bmp:
grUtil.exe 3ColorsG src_picture picture_R  picture_G  picture_B
From 3 colored (or 3 gray) picture make bmp-24:
grUtil.exe fromGray picture_R  picture_G  picture_B dst_picture
Color normalization to inverval 0-255 by each color:
grUtil.exe normalize src_picture dst_picture


Gluing two files

Gluing two files into one horizontally:
grUtil.exe JoinH src_1  src_2 dst_picture
Gluing two files into one vertically:
grUtil.exe JoinV src_1  src_2 dst_picture
Difference: dst := src_1 - src_2 + 128:
grUtil.exe diff src_1  src_2 dst_picture


PSNR, MSE

PSNR(src_1,src_2) -> stdout:
grUtil.exe PSNR src_1  src_2
MSE(src_1,src_2) -> stdout:
grUtil.exe MSE src_1  src_2 


Smoothing and Morphology

Gauss smoothing with radius r:
grUtil.exe smooth  src_picture r dst_picture
Triangle smoothing with radius r:
grUtil.exe smoothT  src_picture r dst_picture
Morphological dilation with radius r:
grUtil.exe morphUp  src_picture r dst_picture
Morphological erosion with radius r:
grUtil.exe morphDn  src_picture r dst_picture
Morphological dilataion-erosion with radius r:
grUtil.exe morphUpDn  src_picture r dst_picture
Morphological erosion-dilataion with radius r:
grUtil.exe morphDnUp  src_picture r dst_picture


Shifts and rotations


Shift by real vector (vx,vy) using bicubic intrepolation:
grUtil.exe shift  src_picture vx vy dst_picture

Shift by real vector (vx,vy) using bilinear intrepolation:
grUtil.exe shift1  src_picture vx vy dst_picture

The rotate around center by alpha degrees + shift(vx,vy) (bicubic intrepolation):
grUtil.exe rot  src_picture alpha vx vy dst_picture

The rotate around center by alpha degrees + shift(vx,vy) (bilinear intrepolation):
grUtil.exe rot1  src_picture alpha vx vy dst_picture


Resize


Resize to mx*my bicubically:
grUtil.exe resize src_picture mx my dst_picture

Resize to mx*my bilinear:
grUtil.exe resize1 src_picture mx my dst_picture

Add a frame of width h filled with zeros:
grUtil.exe border src_picture h dst_picture

Round size down to a multiple of k:
grUtil.exe multiple src_picture k dst_picture

Reduce the size of k times in each dimension (averaging):
grUtil.exe downsize src_picture k dst_picture

Reduce the size of k times in each dimension (thinning pixels):
grUtil.exe downsize2 src_picture k dst_picture


Various methods of the image doubling

Reducing the image size twice can be done in two ways:
  1. Averaging by 2*2-square.
  2. Taking points with even coordinates.
The reverse action in these cases will be slightly different.

1. Back to averaging of the 2*2-square

Sign "+" at the end of the command means additional optimization (see ....).
Trivial doubling (pixel to 2*2 square):

grUtil.exe double0  src_picture dst_picture

Doubling bilinear, bicubic and biquintic:
grUtil.exe double1  src_picture dst_picture
grUtil.exe double1+ src_picture dst_picture
grUtil.exe double3  src_picture dst_picture
grUtil.exe double3+ src_picture dst_picture
grUtil.exe double5  src_picture dst_picture
grUtil.exe double5+ src_picture dst_picture

Lanczos doubling with parameters 1,2,3:
grUtil.exe doubleL1  src_picture dst_picture
grUtil.exe doubleL1+ src_picture dst_picture
grUtil.exe doubleL2  src_picture dst_picture
grUtil.exe doubleL2+ src_picture dst_picture
grUtil.exe doubleL3  src_picture dst_picture
grUtil.exe doubleL3+ src_picture dst_picture

Optimal doubling of degree 1,2,3:
grUtil.exe doubleO1  src_picture dst_picture
grUtil.exe doubleO1+ src_picture dst_picture
grUtil.exe doubleO3  src_picture dst_picture
grUtil.exe doubleO3+ src_picture dst_picture
grUtil.exe doubleO5  src_picture dst_picture
grUtil.exe doubleO5+ src_picture dst_picture

17-point doubling:
grUtil.exe double17  src_picture dst_picture
grUtil.exe double17+ src_picture dst_picture

2. Back to taking points with even coordinates


Bilinear and bicubic doubling :
grUtil.exe 2double1  src_picture dst_picture
grUtil.exe 2double3  src_picture dst_picture


Sprites

The sprite is an image whose RGB color of some points is (0,0,0). When you apply sprites to another image, such points will be skipped.
Create elliptic sprite with given center and semiaxis:
grUtil.exe spr_ell src_picture cx cy ax ay dst_sprite
Create sprite with maximal ellips:
grUtil.exe spr_ellM  src_picture dst_sprite
box-sprite:
grUtil.exe spr_block src_picture x0 y0 dx dy dst_sprite
Apply sprite to the image, center of the sprite goes to (cx,cy):
grUtil.exe spr_put src_picture sprite cx cy dst_picture
Apply sprite to the image with multiplying the size in k (double) times, center of the sprite goes to (cx,cy) with rotation by alpha degrees:
grUtil.exe spr_putR src_picture sprite k cx cy al dst_picture


Create/fill picture with given colors

Create picture of size mx*my of given color:
grUtil.exe make mx my R G B dst_picture
Fill picture of linear colors:
R = r0 + rx*x + ry*y,
G = g0 + gx*x + gy*y,
B = b0 + bx*x + by*y,
grUtil.exe makeL src_picture r0 rx ry g0 gx gy b0 bx by
Fill the interior/exterior of the ellipse with the given centre and axes of RGB color
grUtil.exe fill_el  src_picture cx cy ax ay R G B dst_picture
grUtil.exe fill_elO src_picture cx cy ax ay R G B dst_picture
Fill the inside / outside of the rectangle with RGB color:
grUtil.exe fill_block  src_picture x0 y0 dx dy R G B dst_picture
grUtil.exe fill_blockO src_picture x0 y0 dx dy R G B dst_picture
Create a picture of Ny horizontal stripes h height width mx colors R1 G1 B1 R2 G2 B2:
grUtil.exe stripH R1 G1 B1 R2 G2 B2 h Ny mx dst_picture
Create a picture of Nx vertical stripes width h height my colors R1 G1 B1 R2 G2 B2:
grUtil.exe stripV R1 G1 B1 R2 G2 B2 h Nx my dst_picture
Create a chess picture with colors R1 G1 B1 R2 G2 B2 from Nx*Ny squares of size h
grUtil.exe chess R1 G1 B1 R2 G2 B2 h Nx Ny dst_picture


The Fourier Coefficients

(i,j)-discrete cosine Fourier transform coefficient for the region -> stdio:
grUtil.exe fourier1 src_picture x0 y0 dx dy  i j
All coefficients of the discrete cosine Fourier transform for the region into text matrices fR.txt, fG.txt, fB.txt:
grUtil.exe fourier src_picture x0 y0 dx dy fR.txt, fG.txt, fB.txt


Gradients, derivatives, and variation

gray dst_gray_picture(x,y) := length of gradient of src_picture(x,y)
grUtil.exe grad src_picture dst_gray_picture
dst_picture(x,y) := length of gradient of src_picture(x,y) in each RGB-color
grUtil.exe gradRGB src_picture dst_picture
dst_picture(x,y) := 128 + 2*dx(src)(x,y) in each RGB-color
grUtil.exe dxRGB src_picture dst_picture
Gray picture dst_gray_picture(x,y) := variation of src_picture(x,y)
grUtil.exe variat src_picture dst_gray_picture
dst_picture(x,y) := variaton src_picture(x,y) in each RGB-color:
grUtil.exe variatRGB src_picture dst_gray_picture
Gray picture dst_gray_picture(x,y) := morphological gradient of src_picture(x,y):
grUtil.exe gradM src_picture dst_gray_picture
dst_picture(x,y) := abs(Hessian of src_picture(x,y)) in each RGB-color:
grUtil.exe hessRGB src_picture dst_picture
Gray dst_picture(x,y) := abs(Hessian of src_picture(x,y))
grUtil.exe hess src_picture dst_picture


Show points from two columns of a real matrix in a bmp-file

Show points from two columns (x1,x2) of a real matr.txt in a bmp-file dst_picture of size mx*my by circles of color RGB and radius rad>=0.
min/max in columns -> stdio
grUtil.exe show2C  matr.txt x1 x2 mx my R G B rad dst_picture
Show points from two lines (y1,y2) of a real matr.txt in a bmp-file dst_picture of size mx*my by circles of color RGB and radius rad>=0.
grUtil.exe show2L  matr.txt y1 y2 mx my R G B rad dst_picture


Conversion to b/w

Conversion to b/w via brightness level
grUtil.exe bw  src_picture level dst_picture
Conversion to b/w using the percentage of white dots perc
grUtil.exe bwP  src_picture perc dst_picture
Convert it to gray: the excess of brightness above the average in the area:
grUtil.exe leveling src_picture level dst_picture
Conversion to b/w through the level of excess brightness over the average in the neighborhood:
grUtil.exe bwS  src_picture level dst_picture
Conversion to b/w using the percentage of white dots perc the excess brightness above the average in the area:
grUtil.exe bwSP  src_picture perc dst_picture


Cellular automaton

Cellular automaton with level k (4<k<9): If among 8 neighbors at least k have the same color, then the center point gets the same color.
grUtil.exe cell  src_picture k dst_picture


Palitra

Cause the image to k colors:
grUtil.exe palette  src_picture k dst_picture