X-axis length, that is, gray level axis_params = [] axis_params.append (0) axis_params.append (x_size) #plt.figure () if name! = None: PLT.TITLE (name) PLT.BAR (Tuple (Keys), Tuple (Values))#Draw a histogram #PLT.SHOW () #Map the ash array as a histogram dictionary, nums represents the magnitude of the grayness DEF ArrayTohist (Grayarray, Nums): if (len (grayarray.shape)! = 2): Print (&#8220;length error&#8221;) Return None w, h = Grayarray.shape Hist = {} For K in Range (NUMS): Hist [k] = 0 for I in Range (W): for j in range (h): if (hest.get (grayarray [i] [j]): is none): history [grayarray [i] [j]] = 0 Hist [grayarray [i] [j]] += 1 #normalize n = w*h for key in history.keys (): Hist [key] = float (history [key])/n Return Hist #Accut the cumulative histogram calculating new balanced pictures, nums is grayscale, 256 DEF Equalization (Grayarray, H_S, Nums): #Calculation accumulated histogram TMP = 0.0 h_acc = h_s.copy () for I in Range (256): TMP += H_S [i] h_acc [i] = tmp if (len (grayarray.shape)! = 2): Print (&#8220;length error&#8221;) Return None w, h = Grayarray.shape des = np.zeros ((w, h), dtype = np.uint8) for I in Range (W): for j in range (h): des [i] [j] = int ((nums &#8211; 1)* h_acc [grayarray [i] [j]] +0.5) Return des DEF HISTMATCH (Grayarray, H_D): #Calculation accumulated histogram TMP = 0.0 h_acc = h_d.copy () for I in Range (256): TMP += H_D [i] h_acc [i] = tmp h1 = Arraytohist (Grayarray, 256) TMP = 0.0 h1_acc = h1.copy () for I in Range (256): TMP += H1 [i] h1_acc [i] = tmp #Calculation mapping M = np.zeros (256) for I in Range (256): IDX = 0 minv = 1 for j in h_acc: if (np.fabs (h_acc [j] -h1_acc [i]) <minV): minv = np.fabs (h_acc [j] -h1_acc [i]) IDX = int (j) M [i] = IDX des = m [grayarray] Return des Imdir = "Images/Test_1.jpg"#The path of the original picture imdir_match = "Images/Persian_cat.jpg" # #Open the file and gray im_s = Image.open (IMDIR) .convert ("L") im_s = np.array (IM_S) Print (np.shape (IM_S)) #Open the file and gray im_match = Image.open (imdir_match) .convert ("l") im_match = np.array (im_match) Print (np.shape (IM_MATCH)) #Start drawing PLT.FIGURE () # PLT.SUBPLOT (2,3,1) PLT.TITLE ("Original Picture") PLT.imshow (IM_S, CMAP = 'Gray') PLT.SUBPLOT (2,3,4) hest_s = Arraytohist (IM_S, 256) drawhist (hest_s, "original histogram") #Match picture and its straight chart PLT.SUBPLOT (2,3,2) PLT.TITLE ("MATCH Picture") PLT.imshow (im_match, cmap = 'Gray') PLT.SUBPLOT (2,3,5) hest_m = Arraytohist (im_match, 256) drawhist (hest_m, "match histogram") #Match pictures and its histogram IM_D = HistMatch (im_S, Hist_m)#Use the histogram of the target map to balance the original picture, and it will realize the MATCH PLT.SUBPLOT (2,3,3) PLT.TITLE ("Picture after MATCH") PLT.imshow (im_D, cmap = 'Gray') PLT.SUBPLOT (2,3,6) history_d = Arraytohist (IM_D, 256) drawhist (hist_d, "histogram after mATCH")) PLT.SHOW ()

2023-01-19   ES  

When a project is packaged as UnityPackage, after importing other projects, the customized Tag and Layer in the project will be lost. The following method will automatically write its Tag or Layer into the user’s project when importing the UnityPackage package. Packing the following scripts with resources together, so that when other projects are imported into the UnityPackage package of the project, the program will call Addtag and Addlayer to add. judge.

The following code only adds one tag and a layer, modify the addition of N multiple tags and layers

Put the script under the project

USING System; 
 using system.collections; 
 using system.reflection; 
 using unityeditor; 
 using unityEngine; 
 public class newbehaviourscript: AssetPostProcessor 
 {{ 
     Private Static String [] mytags = {"aaaa", "bbbb", "cccc", "dddd"}; 
     Private Static String [] mylayers = {"aaaa", "bbbb", "cccc", "dddd"}; 

     STATIC VOID ONPOTPROCESSALASSETS (String [] ImportedAssets, String [] deletedAssets, String [] Movedassets, String [] MovedfromasEtPaths) 
     {{ 
         Foreach (String s in ImportEdassets) 
         {{ 
             Ifquals ("Assets/NewBehaviourscript.cs") 
             {{ 
                 Foreach (String tag in mytags) 
                 {{ 
                     Addtag (tag); 
                 } 

                 Foreach (String Layer in Mylayers) 
                 {{ 
                     Addlayer (layer); 
                 } 
                 Addtag ("seld"); <span style = "font-family: arial, helvetica, sans-server; font-size: 12px;"> // Add a tag </span> called Self </span> 
                 AddLayer ("Self"); <span style = "font-family: arial, helvetica, sans-server; font-size: 12px;"> // Add a layer called Ruoruo </span> 
                 Return; 
             } 
         } 
     } 

     Static Void Addtag (String Tag) 
     {{ 
         if (! Ishastag (tag)) 
         {{ 
             SerializedObject Tagmanager = New SerializedObject (AssetDataBase.loadallassetsatpath ("ProjectSettings/Tagmanager.asSet");); 
             Serializedproperty it = tagmanager.getIterator (); 
             While (IT.nextVisible (TRUE))) 
             {{ 
                 if (IT.NAME == "Tags") 
                 {{ 
                     for (int i = 0; I <T.ArraySize; i ++) 
                     {{ 
                         Serializedproperty datapoint = it.getarrayelementatindex (i); 
                         if (String.isnullorempty (DataPoint.StringValue)) 
                         {{ 
                             datapoint.stringvalue = tag; 
                             tagManager.applymodifiedproperties (); 
                             Return; 
                         } 
                     } 
                 } 
             } 
         } 
     } 

     Static Void Addlayer (String Layer) 
     {{ 
         if (! Ishaslayer (layer)) 
         {{ 
             SerializedObject Tagmanager = New SerializedObject (AssetDataBase.loadallassetsatpath ("ProjectSettings/Tagmanager.asSet");); 
             Serializedproperty it = tagmanager.getIterator (); 
             While (IT.nextVisible (TRUE))) 
             {{ 
                 if (IT.NAME.Startswith ("User Layer")) 
                 {{ 
                     if (IT.Type == "String") 
                     {{ 
                         if (String.isnullorempty (it.stringvalue)) 
                         {{ 
                             it.stringvalue = layer; 
                             tagManager.applymodifiedproperties (); 
                             Return; 
                         } 
                     } 
                 } 
             } 
         } 
     } 

     Static Bool Ishastag (String Tag) 
     {{ 
         For (int i = 0; I <unityeditorInterNAL.Internaleditorutility.tags.Length; I ++) 
         {{ 
             if (unityEditorInterinal.internaleditorutility.tags [i] .contains (tag)) 
                 Return true; 
         } 
         Return false; 
     } 

     Static Bool Ishaslayer (String Layer) 
     {{ 
         For (int i = 0; I <UnityEditorInalnal.internaleditorutility.Layers.Length; I ++) 
         {{ 
             if (unityEditorInterinal.internaleditorutility.Layers [i] .contains (layer)) 
                 Return true; 
         } 
         Return false; 
     } 
 }

to MOMO, Original address: http://www.xuanyusong.com/archives/3169

source

Related Posts

Simply achieve the effect of horse rampant lights with code

kotlin declare variables to remove the question mark (?) Use keyword Lateinit

c language -io operation (1) wangs7

C# Partial Class usage

X-axis length, that is, gray level axis_params = [] axis_params.append (0) axis_params.append (x_size) #plt.figure () if name! = None: PLT.TITLE (name) PLT.BAR (Tuple (Keys), Tuple (Values))#Draw a histogram #PLT.SHOW () #Map the ash array as a histogram dictionary, nums represents the magnitude of the grayness DEF ArrayTohist (Grayarray, Nums): if (len (grayarray.shape)! = 2): Print (“length error”) Return None w, h = Grayarray.shape Hist = {} For K in Range (NUMS): Hist [k] = 0 for I in Range (W): for j in range (h): if (hest.get (grayarray [i] [j]): is none): history [grayarray [i] [j]] = 0 Hist [grayarray [i] [j]] += 1 #normalize n = w*h for key in history.keys (): Hist [key] = float (history [key])/n Return Hist #Accut the cumulative histogram calculating new balanced pictures, nums is grayscale, 256 DEF Equalization (Grayarray, H_S, Nums): #Calculation accumulated histogram TMP = 0.0 h_acc = h_s.copy () for I in Range (256): TMP += H_S [i] h_acc [i] = tmp if (len (grayarray.shape)! = 2): Print (“length error”) Return None w, h = Grayarray.shape des = np.zeros ((w, h), dtype = np.uint8) for I in Range (W): for j in range (h): des [i] [j] = int ((nums – 1)* h_acc [grayarray [i] [j]] +0.5) Return des DEF HISTMATCH (Grayarray, H_D): #Calculation accumulated histogram TMP = 0.0 h_acc = h_d.copy () for I in Range (256): TMP += H_D [i] h_acc [i] = tmp h1 = Arraytohist (Grayarray, 256) TMP = 0.0 h1_acc = h1.copy () for I in Range (256): TMP += H1 [i] h1_acc [i] = tmp #Calculation mapping M = np.zeros (256) for I in Range (256): IDX = 0 minv = 1 for j in h_acc: if (np.fabs (h_acc [j] -h1_acc [i])

Random Posts

UNKNOWN HOST ‘DOWNLOADS.Gradle.org‘. You May Need to Adjust The Proxy Settings in Gradle

ListView uses the getView problem NEO

Redhat Linux 6 Install notes

Center 7.5 Install Tomcat+JDK+MySQL (Simple Installation of YUM)

MFC+OpenCV3.3.1+Display image video+water level recognition