In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to deal with python pictures to remove large black areas, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
When using MEGAN software to draw a taxonomic tree, if there are few species, the resulting picture will have a large black area, which is very unattractive.
When using MEGAN software to draw a taxonomic tree, if there are few species, the resulting picture will have a large black area, which is very unattractive. How to remove it, please see the following script:
Script run commands:
Python / share/work/wangq/script/work/png_black.py-I / share/nas1/fanyc/project/zx-20171030-47_21_ITS/2/ITS_3/4.Analysis_output/Taxa_summary/MEGAN_tree/Taxonomic_treeUsage: Options:-I taxonomic tree view the directory where the png picture is located, and also the output directory (do not have "/" at the end of the directory) the program retrieves all png files in the directory and processes The output picture will overwrite the original picture.
Script code:
Import numpyimport sys, os, argparse, os.path,re,mathfrom PIL import Imageimport matplotlib.pyplot as plt#parser = argparse.ArgumentParser (description='This script is used to an error_bar') parser.add_argument Required=True) args = parser.parse_args () pathDir = os.listdir (args.in_dir) for allDir in pathDir: if (re.search (rascpngharmagogy all Dir)): child = os.path.join ('% s bank% s'% (args.in_dir, allDir)) img = Image.open (child) # Imgur's naming scheme pix = numpy.array (img) # Convert to array black = numpy.array 0]) white = numpy.array ([255255255]) black1 = numpy.array ([0Magne0m0255]) white1 = numpy.array ([255255255255]) # print pix print pix [1] pix2 = pix.copy () dim = pix.shape # print pix [1 :] = = black if (dim [2] = = 3): for n in xrange (dim [0]): if (pix [n-force:] = = black). All (): pix2 [n-daginghe-mam numpy.newaxis] = white continue if ((pix [n) :] = = black) .sum () > = 2.7*dim [1]): X = 0 for m in xrange (dim [1]): if (pix [nmemm) :] = = black) .all (): X = xint1 if (x > = dim [1] * 0.9): pix2 [n Reagle Geng Zhi numpy.newaxis] = white # for n in xrange (dim [1]): # if (pix [: N] = = black) .all (): # pix2 [:, nnumpy.newaxis] = white if (dim [2] = = 4): for n in xrange (dim [0]): if (pix [nnumpy:] = = black1). All (): pix2 [n :, numpy.newaxis] = white1 continue if ((pix [NMagne:] = = black1). Sum () > = 3.7*dim [1]): X = 0 for m in xrange (dim [1]): if (pix [NMagnem) :] = = black1) .all (): X = xint1 if (x > = dim [1] * 0.9): pix2 [n Reagle Geng Zhi numpy.newaxis] = white1 # for n in xrange (dim [1]): # if (pix [: N] = = black1) .all (): # pix2 [:, nnumpy.newaxis] = white1 fig = plt.figure () ax = fig.add_axes ([0.0,0.0,1.0,1.0], frameon=False Aspect=1) ax.imshow (pix2) ax.set_xticks ([]) ax.set_yticks ([]) plt.savefig (child,dpi=600) plt.close () # .all () .all () above are all the contents of the article "how to remove large black areas in python" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.