'rgb': [0, 0, 200], 'rgb_b': [200, 200, 0], 'isTransparent': False, 'fontSize': 40, 'yStart': 140, 'xStart': 140 }, { 'text': 'duck', 'rgb': [-50, 0, -50], 'rgb_b': [0, -500, -50], 'isTransparent': True, 'fontSize': 50, 'yStart': 170, 'xStart': 170 }] img = io.imread('.\demo\insertTextImgByRange\duck.jpg') #print(img.shape) tStart = time.time() img_processed = utility.insertTextImgByRange(img, textInfoList) tEnd = time.time() print('Elapsed time is %g seconds.' % (tEnd - tStart)) path = r'.\demo\insertTextImgByRange' dpi = 512 utility.imshow(img, 'original').savefig(os.path.join(path, 'img_original.png'), dpi=dpi) utility.imshow(img_processed, 'processed').savefig(os.path.join(path, 'img_processed.png'), dpi=dpi)
plt.close('all') img_bw, img_gray, img_rgb = loadImg() boundingFilter_bwAndGray = getBoundingFilter_bwAndGray(img_bw) boundingFilter_rgb = getBoundingFilter_rgb(img_rgb) tStart = time.time() img_bw_bounding = utility.getHighLightImg(boundingFilter_bwAndGray, img_bw) img_gray_bounding = utility.getHighLightImg(boundingFilter_bwAndGray, img_gray) img_rgb_bounding = utility.getHighLightImg(boundingFilter_rgb, img_rgb) img_rgb_bounding2 = utility.getHighLightImg(boundingFilter_rgb, img_rgb, rgb=[128, 0, 0], isTransparent=True, rgbBackground=[0,60,0]) img_rgb_bounding3 = utility.getHighLightImg(boundingFilter_rgb, img_rgb, rgb=[-128, -128, 0], isTransparent=True, rgbBackground=[0,60,0]) tEnd = time.time() print('Elapsed time is %g seconds.'%(tEnd-tStart)) ## utility.imshow(img_bw, 'img_bw') utility.imshow(img_gray, 'img_gray') utility.imshow(img_rgb, 'img_rgb') utility.imshow(boundingFilter_bwAndGray, 'boundingFilter_bwAndGray') utility.imshow(boundingFilter_rgb, 'boundingFilter_rgb') utility.imshow(img_bw_bounding, 'img_bw_bounding') utility.imshow(img_gray_bounding, 'img_gray_bounding') utility.imshow(img_rgb_bounding, 'img_rgb_bounding') utility.imshow(img_rgb_bounding2, 'img_rgb_bounding2') utility.imshow(img_rgb_bounding3, 'img_rgb_bounding3') ## #plt.close('all') #img_gray = io.imread(r"./demo/getHighLightImg/_blobs_3d_fiji_skeleton.tif") #img_gray = img_gray[0, :, :] #img_bw = img_gray == 255
sigBackRGB = [255,255,255] fontSize = 20 #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1') #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='LD') #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='RD') #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='RU') #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='LU') #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='LD', sigBackRGB=sigBackRGB) img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='RD', sigBackRGB=sigBackRGB) #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='RU', sigBackRGB=sigBackRGB) #img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='LU', sigBackRGB=sigBackRGB) img = insertSignature(img, featVer='0.0.1', kernelVer='0.0.1-1', loc='LD', fontSize=fontSize) tEnd = time.time() print('Elapsed time is %g seconds.'%(tEnd-tStart)) utility.imshow(img, 'img') #io.imsave(r'.\demo\insertSignature\lena_color_with_signature.png', img) # get 256*256 jet colormap #colors = cm.jet(range(0,256))[:,:3].T #img = np.dstack((colors[0, :], colors[1, :], colors[2, :])) #img = np.tile(img, (256, 1, 1)) # = Matlab's repmat #img_uint8 = (img*255).astype(np.uint8) #utility.imshow(img, 'img').axis('off') #utility.imshow(img_uint8, 'img_uint8').axis('off') # get 256*256 jet colormap: Matlab #colors = jet(256); #colors = colors'; #img = cat(3, colors(1, :), colors(2, :), colors(3, :)); #img = repmat(img, [256, 1]);
isTransparent=True, rgbBackground=[50, 50, 0]) img_bw_demo = utility.getHighLightImgByRange(stringImg, img_bw, yStart, xStart) img_bw_demo2 = utility.getHighLightImgByRange(stringImg, img_bw, yStart, xStart, rgb=[0, 0, 50], isTransparent=True, rgbBackground=[50, 50, 0]) tEnd = time.time() print('Elapsed time is %g seconds.' % (tEnd - tStart)) path = r'.\demo\getHighLightImgByRange' dpi = 512 utility.imshow(stringImg).savefig(r'%s\%s.png' % (path, 'stringImg'), dip=dpi) utility.imshow(img_rgb).savefig(r'%s\%s.png' % (path, 'img_rgb'), dip=dpi) utility.imshow(img_gray).savefig(r'%s\%s.png' % (path, 'img_gray'), dip=dpi) utility.imshow(img_bw).savefig(r'%s\%s.png' % (path, 'img_bw'), dip=dpi) utility.imshow(img_rgb_demo) utility.imshow(img_rgb_demo2) utility.imshow(img_gray_demo) utility.imshow(img_gray_demo2) utility.imshow(img_bw_demo) utility.imshow(img_bw_demo2) io.imsave(r'%s\%s.png' % (path, 'img_rgb_demo'), img_rgb_demo) io.imsave(r'%s\%s.png' % (path, 'img_rgb_demo2'), img_rgb_demo2) io.imsave(r'%s\%s.png' % (path, 'img_gray_demo'), img_gray_demo) io.imsave(r'%s\%s.png' % (path, 'img_gray_demo2'), img_gray_demo2)
# -*- coding: utf-8 -*- import matplotlib.pyplot as plt import utility from skimage import transform import time plt.close('all') text = r'''abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()-_=+[{]}\|;:'",<.>/? 我''' tStart = time.time() stringImg = utility.getStringImg_10(text) tEnd = time.time() print('Elapsed time is %g seconds.' % (tEnd - tStart)) #stringImg2 = transform.rescale(stringImg, 1.5, order=0) utility.imshow(stringImg) font = 'EightBitDragon_anqx' tStart = time.time() stringImg = utility.getStringImg_10(text, font=font) tEnd = time.time() print('Elapsed time is %g seconds.' % (tEnd - tStart)) stringImg2 = transform.rescale(stringImg, 1.5, order=0) utility.imshow(stringImg, 'font: %s' % (font)) text = r'Hello World !' stringImg = utility.getStringImg_10(text) #utility.imshow(stringImg).savefig('.\demo\getStringImg_20\stringImg_20_demo.png', dip=512) text = r'a' stringImg = utility.getStringImg_10(text) utility.imshow(stringImg)
# -*- coding: utf-8 -*- import utility from skimage import io import os from utility.getFontTemplateImg import getFontTemplateImg import matplotlib.pyplot as plt if __name__ == '__main__': plt.close('all') # font_path = r'.\demo\font\EightBitDragon-anqx.ttf' font_path = r'.\demo\font\1_Minecraft-Regular.otf' imgH = 20 # = font_size imgW = 1300 # y_ori = 0 y_ori = -2 fontTemplateImg = getFontTemplateImg(imgH, imgW, font_path, y_ori=y_ori) font_file_name = os.path.splitext(os.path.basename(font_path))[0] # get fileName without extention io.imsave(r'.\demo\font_template\font_template_%s.png'%(font_file_name), fontTemplateImg) utility.imshow(fontTemplateImg, 'fontTemplateImg') #a = np.array([[0,1,0], [1,1,0], [1,0,0]], np.bool) #rows, cols = np.nonzero(a) #b = np.zeros(a.shape, np.bool) #b[rows, cols] = True
img_rgb_R = np.dstack((img255, img0, img0)) img_rgb_G = np.dstack((img0, img255, img0)) img_rgb_B = np.dstack((img0, img0, img255)) return img_rgb_black, img_rgb_gray, img_rgb_white, img_rgb_R, img_rgb_G, img_rgb_B plt.close('all') img_bw_false, img_bw_true, img_bw_mix = getImgBw() img_gray_0, img_gray_127, img_gray_255, img_gray_mix = getImgGray() img_rgb_black, img_rgb_gray, img_rgb_white, img_rgb_R, img_rgb_G, img_rgb_B = getImgRgb( ) dpi = 128 utility.imshow(img_bw_false, 'img_bw_false').savefig(r'.\demo\imshow\img_bw_false.png', dpi=dpi) utility.imshow(img_bw_true, 'img_bw_true').savefig(r'.\demo\imshow\img_bw_true.png', dpi=dpi) utility.imshow(img_bw_mix, 'img_bw_mix').savefig(r'.\demo\imshow\img_bw_mix.png', dpi=dpi) utility.imshow(img_gray_0, 'img_gray_0').savefig(r'.\demo\imshow\img_gray_0.png', dpi=dpi) utility.imshow(img_gray_127, 'img_gray_127').savefig(r'.\demo\imshow\img_gray_127.png', dpi=dpi) utility.imshow(img_gray_255, 'img_gray_255').savefig(r'.\demo\imshow\img_gray_255.png', dpi=dpi) utility.imshow(img_gray_mix,
import utility import matplotlib.pyplot as plt plt.close('all') demoPath = r'.\demo\getEllipseBwImg' imgH = 512 imgW = 1024 ellipseBwImg = [] #ellipseBwImg = np.zeros((imgH, imgW), np.bool); #ellipseBwImg[50:200, 50:200] = True if __name__ == '__main__': ellipseBwImg_matlab = np.array( Image.open(os.path.join(demoPath, 'ellipseBwImg_matlab.png'))) utility.imshow(ellipseBwImg_matlab, 'ellipseBwImg_matlab') ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 256 - 1, 512 - 1, 64, 128, 15, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 128 - 1, 256 - 1, 32, 64, -30, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 256 + 128 - 1, 256 - 1, 32, 64, 30, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 512 - 1, 256 + 512 - 1, 512, 64, 30, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 512 - 1, 256 - 1, 64, 512, 0, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 256 - 1, 90 - 1, 128, 64, 0, ellipseBwImg) ellipseBwImg = utility.getEllipseBwImg(imgH, imgW, 87 - 1, 685 - 1, 512, 30, -45, ellipseBwImg)
{'text': 'kernel ver.: %s'%('0.0.1'), 'rgb': rgb, 'rgb_b': [100,0,-50]}]) descp_text.append([{'text': 'descp3: xx', 'rgb': rgb, 'rgb_b': rgb_b}, {}, {'text': 'other info: xx', 'rgb': rgb, 'rgb_b': rgb_b}]) descp_test_start_y = [(imgH + gap_ver) * len(img_list), (imgH + gap_ver) * len(img_list)] descp_test_start_x = [0 + 5, (imgW + gap_hoz) * 2 + 5] tStart = time.time() mergedDemoImg = utility.getMergeDemoImgNoFont(rgb,rgb_b,rgb_demo, row_num,col_num,font_size,gap_ver,gap_hoz, descp_height,imgH,imgW, img_list,descp_text,descp_test_start_y,descp_test_start_x) tEnd = time.time() print('Elapsed time is %g seconds.'%(tEnd-tStart)) utility.imshow(mergedDemoImg, 'mergedDemoImg') #io.imsave(r'%s\%s.png'%(demoPath, 'mergedDemoImg'), mergedDemoImg)