Best Python code snippet using localstack_python
main.py
Source:main.py
...13 """14 runs a separation on specific two images15 :return:16 """17 # im1 = prepare_image('data/kate.png')18 # im2 = prepare_image('data/f16.png')19 # mixed = mix_images(im1, im2)20 21 # im1 = prepare_image('data/bear.jpg')22 # im2 = prepare_image('data/players.jpg')23 # mixed = prepare_image("data/separation/difference.bmp")24 # mixed, kernel, ratio = realistic_mix_images(im1, im2)25 # mixed = prepare_image('data/separation/postcard/ae-5-m-11.png')26 # mixed = prepare_image('data/separation/solid/m.jpg')27 # im1 = prepare_image('data/separation/g.jpg')28 # ----29 # im2 = prepare_image('data/separation/dorm1_input.png')30 #31 # s = Separation("dorm", im2, num_iter=4000)32 # s.optimize()33 # s.finalize()34 #35 # im2 = prepare_image('data/separation/dusk2_input.png')36 # im2 = np_imresize(im2, 0.5)37 #38 #39 # s = Separation("dusk", im2, num_iter=4000)40 # s.optimize()41 # s.finalize()42 im2 = prepare_image('data/separation/bus_station_input.png')43 s = Separation("bus_station", im2, num_iter=4000)44 s.optimize()45 s.finalize()46 im2 = prepare_image('data/separation/night3_input.png')47 im2 = np_imresize(im2, 0.5)48 s = Separation("night", im2, num_iter=4000)49 s.optimize()50 s.finalize()51 im2 = prepare_image('data/separation/dusk_input.png')52 s = Separation("dusj1", im2, num_iter=4000)53 s.optimize()54 s.finalize()55def experiment_example():56 im1 = prepare_image('data/experiments/texture3.jpg')57 im2 = prepare_image('data/experiments/texture1.jpg')58 mixed = (im1 + im2) / 259 # mixed = prepare_gray_image('data/experiments/97033.jpg')60 # mixed = prepare_gray_image('data/separation/c.jpg')61 s = Separation("mixed", mixed, num_iter=8000)62 s.optimize()63 s.finalize()64def ambiguity_experiment_example():65 im1 = prepare_image('data/experiments/texture3.jpg')66 im2 = prepare_image('data/experiments/texture1.jpg')67 im3 = prepare_image('data/experiments/texture4.jpg')68 im4 = prepare_image('data/experiments/texture6.jpg')69 im1_new = im170 im1_new[:,:, :im1.shape[2]//2] = im4[:,:, :im1.shape[2]//2]71 im2_new = im272 # im4 = np_imresize(im4, output_shape=im2.shape)73 im2_new[:, :, :im2.shape[2] // 2] = im3[:,:, :im2.shape[2] // 2]74 save_image("input1", im1_new)75 save_image("input2", im2_new)76 mixed =(im1_new + im2_new) / 277 save_image("mixed", mixed)78 exit()79 for i in range(10):80 # mixed = prepare_gray_image('data/experiments/97033.jpg')81 # mixed = prepare_gray_image('data/separation/c.jpg')82 s = Separation("mixed_{}".format(i), mixed, num_iter=8000)83 s.optimize()84 s.finalize()85def segment_example():86 # for i in range(1, 10):87 im = prepare_image('data/segmentation/zebra.png')88 fg = prepare_image('data/segmentation/zebra_fg - Copy.png')89 bg = prepare_image('data/segmentation/zebra_bg - Copy.png')90 # fg = prepare_image('data/segmentation/zebra_5_mask.bmp')91 # bg = 1 - prepare_image('data/segmentation/zebra_5_mask.bmp')92 # fg = prepare_image('data/segmentation/zebra_saliency.bmp')93 # fg[fg > 0.9] = 194 # fg[fg <= 0.9] = 095 # bg = 1 - prepare_image('data/segmentation/zebra_saliency.bmp')96 # bg[bg > 0.9] = 197 # bg[bg <= 0.9] = 098 s = Segmentation("zebra_{}".format(1), im, bg_hint=bg, fg_hint=fg)99 s.optimize()100 s.finalize()101 # im = prepare_image('data/segmentation/sheep.jpg')102 # fg = prepare_image('data/segmentation/sheep_fg.png')103 # bg = prepare_image('data/segmentation/sheep_bg.png')104 #105 # s = Segmentation("sheep", im, bg_hint=bg, fg_hint=fg)106 # s.optimize()107 # s.finalize()108 # im = prepare_image('data/segmentation/yaks.jpg')109 # fg = prepare_image('data/segmentation/yaks_fg.png')110 # bg = prepare_image('data/segmentation/yaks_bg.png')111 #112 # s = Segmentation("yaks", im, step_num=2, bg_hint=bg, fg_hint=fg)113 # s.optimize()114 # s.finalize()115 #116 # im = prepare_image('data/segmentation/pagoda.jpg')117 # fg = prepare_image('data/segmentation/pagoda_fg.png')118 # bg = prepare_image('data/segmentation/pagoda_bg.png')119 # s = Segmentation("pagoda", im, step_num=2, bg_hint=bg, fg_hint=fg)120 # s.optimize()121 # s.finalize()122 # im = prepare_image('data/elephant.jpg')123 # im = prepare_image('data/segmentation/pagoda.jpg')124 # im = prepare_image('data/segmentation/361010.jpg')125 # im = prepare_image('data/segmentation/image014.jpg')126 # im = prepare_image('data/segmentation/demo.png')127 # im = prepare_image('data/segmentation/image005.png')128 # im = prepare_image('data/segmentation/image015.png')129 # im = prepare_image('data/segmentation/img_1029.jpg')130 # im = np.clip(imresize(im.transpose(1, 2, 0), 0.5).transpose(2, 0, 1), 0, 1)131 # bg = np.clip(imresize(bg.transpose(1, 2, 0), 0.5).transpose(2, 0, 1), 0, 1)132 # fg = np.clip(imresize(fg.transpose(1, 2, 0), 0.5).transpose(2, 0, 1), 0, 1)133 # segment(im)134 # uneven_segment(im, show_every=500)135 # multiscale_segment(im)136 # uneven_multiscale_segment(im)137def dehazing_exmaple():138 # im = prepare_image('data/dehazing/forest.png')139 # im = prepare_image('data/dehazing/tiananmen.png')140 im = prepare_image('data/dehazing/cityscape.png')141 # im = prepare_image('data/dehazing/dubai.png')142 # im = prepare_image('data/dehazing/mountain.png')143 # im = prepare_image('data/dehazing/underwaterWaterTank.jpg')144 # dehaze(im, use_deep_channel_prior=True)145def watermark_example():146 # im = prepare_image('data/watermark/fotolia.jpg')147 # fg = prepare_image('data/watermark/fotolia_watermark.png')148 # remove_watermark("fotolia", im, fg)149 #150 # im = prepare_image('data/watermark/copyright.jpg')151 # fg = prepare_image('data/watermark/copyright_watermark.png')152 # remove_watermark("copyright", im, fg)153 #154 # im = prepare_image('data/watermark/small_portubation.jpg')155 # fg = prepare_image('data/watermark/small_portubation_watermark.png')156 # remove_watermark("small_portubation", im, fg)157 # im = prepare_image('data/watermark/cvpr1.jpg')158 # fg = prepare_image('data/watermark/cvpr1_watermark.png')159 # remove_watermark("cvpr1", im, fg)160 #161 # im = prepare_image('data/watermark/cvpr2.jpg')162 # fg = prepare_image('data/watermark/cvpr2_watermark.png')163 # remove_watermark("cvpr2", im, fg)164 # im = prepare_image('data/watermark/coco.jpg')165 # fg = prepare_image('data/watermark/coco_watermark.png')166 # remove_watermark("coco", im, fg)167 #168 # im = prepare_image('data/watermark/coco2.jpg')169 # fg = prepare_image('data/watermark/coco2_watermark.png')170 # remove_watermark("coco2", im, fg)171 # im = prepare_image('data/watermark/cvpr3.jpg')172 # fg = prepare_image('data/watermark/cvpr3_watermark.png')173 # remove_watermark("cvpr3", im, fg)174 # im = prepare_image('data/watermark/cvpr4.jpg')175 # fg = prepare_image('data/watermark/cvpr4_watermark.png')176 # remove_watermark("cvpr4", im, fg)177 # im = prepare_image('data/watermark/AdobeStock1.jpg')178 # fg = prepare_image('data/watermark/AdobeStock1_watermark.png')179 # remove_watermark("AdobeStock1", im, fg)180 # im = prepare_image('data/watermark/AdobeStock2.jpg')181 # fg = prepare_image('data/watermark/AdobeStock2_watermark.png')182 # remove_watermark("AdobeStock2", im, fg)183 # im = prepare_image('data/watermark/AdobeStock3.jpg')184 # fg = prepare_image('data/watermark/AdobeStock3_watermark.png')185 # remove_watermark("AdobeStock3", im, fg)186 # im = prepare_image('data/watermark/AdobeStock4.jpg')187 # fg = prepare_image('data/watermark/AdobeStock4_watermark.png')188 # remove_watermark("AdobeStock4", im, fg)189 im = prepare_image('data/watermark/AdobeStock5.jpg')190 fg = prepare_image('data/watermark/AdobeStock5_watermark.png')191 remove_watermark("AdobeStock5", im, fg)192def watermark2_example():193 im1 = prepare_image('data/watermark/fotolia1.jpg')194 im2 = prepare_image('data/watermark/fotolia2.jpg')195 fg = prepare_image('data/watermark/fotolia_many_watermark.png')196 results = []197 for i in range(7):198 # TODO: make it median199 s = TwoImagesWatermark("fotolia_example_{}".format(i), im1, im2, step_num=2, watermark_hint=fg)200 s.optimize()201 s.finalize()202def watermarks2_example_no_hint():203 # im1 = prepare_image('data/watermark/123RF_1.jpg')204 # im2 = prepare_image('data/watermark/123RF_2.jpg')205 # im3 = prepare_image('data/watermark/123RF_3.jpg')206 # im4 = prepare_image('data/watermark/123RF_4.jpg')207 # results = []208 # for i in range(7):209 # # TODO: make it median210 # s = ManyImagesWatermarkNoHint(["123rf_example_{}".format(i) for i in range(4)], [im1, im2, im3, im4])211 # s.optimize()212 # s.finalize()213 im1 = prepare_image('data/watermark/fotolia1.jpg')214 im2 = prepare_image('data/watermark/fotolia2.jpg')215 im3 = prepare_image('data/watermark/fotolia3.jpg')216 results = []217 for i in range(5):218 # TODO: make it median219 s = ManyImagesWatermarkNoHint(["fotolia_example_{}".format(i) for i in range(3)], [im1, im2, im3])220 s.optimize()221 results.append(s.best_result)222 # namedtuple("ManyImageWatermarkResult", ['cleans', 'mask', 'watermark', 'psnr'])223 obtained_watermark = median([result.mask * result.watermark for result in results])224 obtained_im1 = median([result.cleans[0] for result in results])225 obtained_im2 = median([result.cleans[1] for result in results])226 obtained_im3 = median([result.cleans[2] for result in results])227 # obtained_mask = median([result.mask for result in results])228 v = np.zeros_like(obtained_watermark)229 v[obtained_watermark < 0.03] = 1230 final_im1 = v * im1 + (1 - v) * obtained_im1231 final_im2 = v * im2 + (1 - v) * obtained_im2232 final_im3 = v * im3 + (1 - v) * obtained_im3233 save_image("fotolia1_final", final_im1)234 save_image("fotolia2_final", final_im2)235 save_image("fotolia3_final", final_im3)236 save_image("fotolia_final_watermark", obtained_watermark)237 # TODO: for watermark - zero everything under 0.03238def two_extending_experiment():239 im1 = prepare_image('data/kate.png')240 im2 = prepare_image('data/f16.png')241 t = SeparationExtendingExperiment("kate_f16", im1, im2, 2000, True)242 t.optimize()243 t.finalize()244def separate_image_video_example():245 # vid = prepare_video('data/separation/vid.avi')246 # vid = prepare_video('data/separation/half_horses.mp4')247 vid = prepare_video('data/separation/fountain_short.mp4')248 im = prepare_image('data/separation/d.jpg')249 im = np_imresize(im, output_shape=vid.shape[2:])250 mix = 0.5 * im + 0.5 * vid251 image_video_separation("tiger", mix)252 vid = prepare_video('data/separation/fountain_short.mp4')253 im = prepare_image('data/separation/f.jpg')254 im = np_imresize(im, output_shape=vid.shape[2:])255 mix = 0.5 * im + 0.5 * vid256 image_video_separation("misg", mix)257 vid = prepare_video('data/separation/horses_short.mp4')258 im = prepare_image('data/separation/g.jpg')259 im = np_imresize(im, output_shape=vid.shape[2:])260 mix = 0.5 * im + 0.5 * vid261 image_video_separation("cow", mix)262def separate_video_video_example():263 vid = prepare_video('data/separation/fountain_horses.mp4')264 s = VideoVideoSeparation("fountain_horses", vid)265 s.optimize()266 s.finalize()267def separate_alpha_video_example():268 vid = prepare_video('data/separation/vid.avi')269 image_video_separation_with_alpha("video_alpha", vid)270def separate_alpha_video_video_example():271 vid = prepare_video('data/separation/vid.avi')272 alpha_video_video_separation("video_alpha", vid)...
stardict_images.py
Source:stardict_images.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3from gimpfu import *4import os5def prepare_image(image, visibleLayers, size, numColors = None):6 """prepare custom image7 image - image object to change8 size - size of the image in pixels9 visibleLayers - a list of layers that must be visible10 """11 for layer in image.layers:12 if layer.name in visibleLayers:13 layer.visible = True14 else:15 image.remove_layer(layer)16 gimp.pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE)17 drawable=gimp.pdb.gimp_image_get_active_layer(image)18 gimp.pdb.gimp_layer_scale_full(drawable, size, size, False, INTERPOLATION_CUBIC)19 """20 image 670x670, all layers have the same dimensions21 after applying gimp_image_scale_full functions with size=32,22 image.width = 32, image.height = 3223 layer.width = 27, layer.height = 3124 gimp.pdb.gimp_image_scale_full(image, size, size, INTERPOLATION_CUBIC)25 """26 #print 'width = {0}, height = {1}'.format(drawable.width, drawable.height)27 #print 'width = {0}, height = {1}'.format(image.width, image.height)28 if numColors != None:29 gimp.pdb.gimp_image_convert_indexed(image, NO_DITHER, MAKE_PALETTE, numColors, False, False, "")30def save_image(image, dstFilePath):31 dirPath = os.path.dirname(dstFilePath)32 if not os.path.exists(dirPath):33 os.makedirs(dirPath)34 drawable=gimp.pdb.gimp_image_get_active_layer(image)35 gimp.pdb.gimp_file_save(image, drawable, dstFilePath, dstFilePath)36 gimp.delete(drawable)37 gimp.delete(image)38def create_icon(origImage, visibleLayers, props):39 """visibleLayers - a list of layers that must be visible40 props - tuple of image properties in format ((size, bpp), ...)41 where: 42 size - size of the icon in pixels,43 bpp - bits per pixel, None to leave by default44 return value - new image45 """46 iconImage = None47 i = 048 for prop in props:49 image = gimp.pdb.gimp_image_duplicate(origImage)50 prepare_image(image, visibleLayers, prop[0], prop[1])51 image.layers[0].name = 's{0}'.format(i)52 if iconImage == None:53 iconImage = image54 else:55 newLayer = gimp.pdb.gimp_layer_new_from_drawable(image.layers[0], iconImage)56 gimp.pdb.gimp_image_add_layer(iconImage, newLayer, -1)57 gimp.delete(image)58 i += 159 60 return iconImage61 62def stardict_images(srcFilePath, rootDir):63 if not rootDir:64 # srcFilePath = rootDir + "/pixmaps/stardict.xcf"65 if not srcFilePath.endswith("/pixmaps/stardict.xcf"):66 print 'Unable to automatically detect StarDict root directory. Specify non-blank root directory parameter.'67 return68 dstDirPath = os.path.dirname(srcFilePath)69 dstDirPath = os.path.dirname(dstDirPath)70 else:71 dstDirPath = rootDir72 """73 print 'srcFilePath = {0}'.format(srcFilePath)74 print 'rootDir = {0}'.format(rootDir)75 print 'dstDirPath = {0}'.format(dstDirPath)76 """77 dstStarDict_s128_FilePath=os.path.join(dstDirPath, "pixmaps/stardict_128.png")78 dstStarDict_s32_FilePath=os.path.join(dstDirPath, "pixmaps/stardict_32.png")79 dstStarDict_s16_FilePath=os.path.join(dstDirPath, "pixmaps/stardict_16.png")80 dstStarDict_FilePath=os.path.join(dstDirPath, "pixmaps/stardict.png")81 dstStarDictEditor_s128_FilePath=os.path.join(dstDirPath, "pixmaps/stardict-editor_128.png")82 dstStarDictEditor_s32_FilePath=os.path.join(dstDirPath, "pixmaps/stardict-editor_32.png")83 dstStarDictEditor_s16_FilePath=os.path.join(dstDirPath, "pixmaps/stardict-editor_16.png")84 dstStarDictIconFilePath=os.path.join(dstDirPath, "pixmaps/stardict.ico")85 dstStarDictEditorIconFilePath=os.path.join(dstDirPath, "pixmaps/stardict-editor.ico")86 dstStarDictUninstIconFilePath=os.path.join(dstDirPath, "pixmaps/stardict-uninst.ico")87 dstDockletNormalFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_normal.png")88 dstDockletScanFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_scan.png")89 dstDockletStopFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_stop.png")90 dstDockletGPENormalFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_gpe_normal.png")91 dstDockletGPEScanFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_gpe_scan.png")92 dstDockletGPEStopFilePath=os.path.join(dstDirPath, "src/pixmaps/docklet_gpe_stop.png")93 dstWordPickFilePath=os.path.join(dstDirPath, "src/win32/acrobat/win32/wordPick.bmp")94 95 origImage=gimp.pdb.gimp_file_load(srcFilePath, srcFilePath)96 97 image = gimp.pdb.gimp_image_duplicate(origImage)98 prepare_image(image, ("book1", "book2"), 128)99 save_image(image, dstStarDict_s128_FilePath)100 image = gimp.pdb.gimp_image_duplicate(origImage)101 prepare_image(image, ("book1", "book2"), 32)102 save_image(image, dstStarDict_s32_FilePath)103 image = gimp.pdb.gimp_image_duplicate(origImage)104 prepare_image(image, ("book1", "book2"), 16)105 save_image(image, dstStarDict_s16_FilePath)106 image = gimp.pdb.gimp_image_duplicate(origImage)107 prepare_image(image, ("book1", "book2"), 64)108 save_image(image, dstStarDict_FilePath)109 image = gimp.pdb.gimp_image_duplicate(origImage)110 prepare_image(image, ("book1", "book2", "edit"), 128)111 save_image(image, dstStarDictEditor_s128_FilePath)112 image = gimp.pdb.gimp_image_duplicate(origImage)113 prepare_image(image, ("book1", "book2", "edit"), 32)114 save_image(image, dstStarDictEditor_s32_FilePath)115 image = gimp.pdb.gimp_image_duplicate(origImage)116 prepare_image(image, ("book1", "book2", "edit"), 16)117 save_image(image, dstStarDictEditor_s16_FilePath)118 image = create_icon(origImage, ("book1", "book2"),119 ((16, None), (32, None), (48, None), (16, 256), (32, 256), (48, 256), (256, None))120 )121 save_image(image, dstStarDictIconFilePath)122 123 image = create_icon(origImage, ("book1", "book2", "edit"),124 ((16, None), (32, None), (48, None), (16, 256), (32, 256), (48, 256), (256, None))125 )126 save_image(image, dstStarDictEditorIconFilePath)127 128 image = create_icon(origImage, ("book1", "book2", "cross"),129 ((16, None), (32, None), (48, None), (16, 256), (32, 256), (48, 256), (256, None))130 )131 save_image(image, dstStarDictUninstIconFilePath)132 133 image = gimp.pdb.gimp_image_duplicate(origImage)134 prepare_image(image, ("book1", "book2"), 32)135 save_image(image, dstDockletNormalFilePath)136 image = gimp.pdb.gimp_image_duplicate(origImage)137 prepare_image(image, ("book1", "book2", "search"), 32)138 save_image(image, dstDockletScanFilePath)139 image = gimp.pdb.gimp_image_duplicate(origImage)140 prepare_image(image, ("book1", "book2", "stop"), 32)141 save_image(image, dstDockletStopFilePath)142 image = gimp.pdb.gimp_image_duplicate(origImage)143 prepare_image(image, ("book1", "book2"), 16)144 save_image(image, dstDockletGPENormalFilePath)145 image = gimp.pdb.gimp_image_duplicate(origImage)146 prepare_image(image, ("book1", "book2", "search"), 16)147 save_image(image, dstDockletGPEScanFilePath)148 image = gimp.pdb.gimp_image_duplicate(origImage)149 prepare_image(image, ("book1", "book2", "stop"), 16)150 save_image(image, dstDockletGPEStopFilePath)151 # See AVToolButtonNew function in PDF API Reference152 # Recommended icon size is 18x18, but it looks too small...153 image = gimp.pdb.gimp_image_duplicate(origImage)154 prepare_image(image, ("book1", "book2"), 22)155 gimp.set_background(192, 192, 192)156 gimp.pdb.gimp_layer_flatten(image.layers[0])157 save_image(image, dstWordPickFilePath)158register(159 "stardict_images",160 "Create images for StarDict",161 "Create images for StarDict",162 "StarDict team",163 "GPL",164 "Mar 2011",165 "<Toolbox>/Tools/stardict images",166 "",167 [168 (PF_FILE, "src_image", "Multilayer image used as source for all other images in StarDict, "...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!