images: module of image tools

PyHdust images module: auxiliary images module

# ramp yellow sz = 100 r = _np.arange(sz*sz).reshape((sz,sz))*256./sz/sz g = _np.arange(sz*sz).reshape((sz,sz))*256./sz/sz b = _np.zeros((sz,sz)) yramp = _np.dstack((r,g,b)).astype(uint8)

img = PIL.Image.fromarray(yramp)‘yrampRGB.jpg’)

img = PIL.Image.fromarray(rgb2cmyk(yramp), mode=’CMYK’)‘yrampCMYK.jpg’)

# convert ‘CMYK_color’ CM =‘CMYK_color.jpg’) CM = CM.convert(mode=’RGB’)‘CMYK2rgbPIL.jpg’)

img = PIL.Image.fromarray(rgb2cmyk(_np.asarray(CM)), mode=’CMYK’)‘CMYK2rgb.jpg’)

license:GNU GPL v3.0
pyhdust.images.align_backfore(bkimg, frimg, pos=[0.1, 0.9])[source]


pyhdust.images.doColorConv(lbd, flx, fdat=None)[source]

fdat is and (3,nlbd) matrix with the color space functions. If None, CIE 1931 RGB color space is used.

INPUT = lambda (nm), flux (intensities) vectors

OUTPUT = RGB values (0-255; uint8)

pyhdust.images.doColorConvMaps(data, lbdc, fdat=None, di=0, oi=0, ii=0, outflt=False)[source]

fdat is and (3,nlbd) matrix with the color space functions. If None, CIE 1931 RGB color space is used.

di, oi, ii are data[oi, ii, di]. di = 0 for *.maps files.

outflt=True, the output is in float format.

INPUT = data (n,m,nlbdc), lambda (nlbdc; um unit)

OUTPUT = RGB images (n,m,3; [0-255; uint8])

pyhdust.images.doHDR(RGB, levels=6, folder='hdr', ext='png', strength=[1.0], naturalness=[1.0], size=None)[source]

Do HDR of RGB images.

pyhdust.images.do_background(foreimg, backimg, savename=None, pos=[0.1, 0.9], cut=0.5, fmt=['png'], bga=0.9, rotang=0.0, fsize=None)[source]

Add backimg as background (bg) of foreimg (fg). *img are regular image files (e.g., JPG or PNG).

pos is the position of the central pixel of fg as fraction size of the bg image. Example: pos = [.1, .1] puts the foreground image in the lowe left position; pos = [.5, .5] in the center.

cut = limit the brightest pixels. cut == 1 says that only white points will have no background (transparency. In other words, all fg will be transparent as bg). cut == 0.5 says that every pixel with >= 50% of the white level will not be transparent. cut == 0 says that all black points will not be transparent (i.e., no bg).

bga = background strength

METHOD: There the fg is brillhant (star), no bg. Where it is tenous, (disk), it is applied a combination of bg + fg with the transparency is proportiona to the fg brightness.

Is it important to note that even if a “black background” is applied, the disk will be atenuated where it is below the cutting limit.

DETAILS: a combination of images, without saturation (standard level) is equal to (img1 + img2 )/2.

Problem 1: the star becomes transparent! Solution: we define a cut, where pixels above a given level do not enter in the above sum, rather their foreground values are kept.

Problem 2: this procedure can create a big contrast between the star and the disk, making the disk 50% fainter. Solucion: define the transparency as function of the fg value (bigger the value, less transparent).

Problem 3: if the star is seen edge-on, one can have bg where it is the star! How to solve it? Analogous to the cut, if an mask can be created if the photospheric image is provided (and then, no gb where px_val > 0).

TODO: photospheric mask to cut.

pyhdust.images.genGaussian(size=64, sig=8, center=(0, 0))[source]

Generate a square gaussian kernel (non-normalized).

size is the length of a side of the square (pixels)

center is the relative position

pyhdust.images.genSquare(size=64, halfside=16, center=(0, 0))[source]

Generate a square inside a square.

If size is not even, the unit square will not be centered.

center is the relative position


img must have (m,n,3) dimensions

R’ = R/255

G’ = G/255

B’ = B/255

The black key (K) color is calculated from the red (R’), green (G’) and blue (B’) colors:

K = min(R’, G’, B’)

The cyan color (C) is calculated from the red (R’) and black (K) colors:

C = (1-R’-K) / (1-K)

The magenta color (M) is calculated from the green (G’) and black (K) colors:

M = (1-G’-K) / (1-K)

The yellow color (Y) is calculated from the blue (B’) and black (K) colors:

Y = (1-B’-K) / (1-K)

pyhdust.images.rgb2png(RGB, savename=None, ext='png', size=None)[source]

Save a array(n,m,3; uint8) as regular image file.

pyhdust.images.rotate_coords(x, y, theta, ox, oy)[source]

Rotate arrays of coordinates x and y by theta radians about the point (ox, oy).

This routine was inspired on a post.

pyhdust.images.rotate_cube(src, theta, ox=None, oy=None, fill=0)[source]

src must be a numpy array.

pyhdust.images.rotate_image(src, theta, ox=None, oy=None, fill=0)[source]

Rotate the image src by theta radians about (ox, oy). Pixels in the result that don’t correspond to pixels in src are replaced by the value fill.

This routine was inspired on a post.