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-03-14  

1.AJAX -Basic operation of request

After clicking the sending request, the response will be printed in the window below



在这里插入图片描述
ajaxDemo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax get request</title>
    <style>
        #result {
      
            width: 200px;
            height: 100px;
            border: solid 1px #CCC;
        }
    </style>
</head>
<body>
<button>Click to send request</button>
<div id="result"></div>

<script>
</script>
</body>
</html>

在这里插入图片描述
server.js

// 1. Introduce Express
const express = require('express');

// 2. Create application objects
const app = express();

// 3. Create routing rules
// Request is the package of the request message
// Response is a package of the response message
app.get('/server', (request, response) => {
    
    // Set the response => Allow cross -domain
    response.setHeader('Access-Control-Allow-Origin', '*');
    // Set response
    response.send('HELLO EXPRESS');
});

// 4. Surveillance port startup service
app.listen(8000, () => {
    
    console.log("The service has been started, and the 8000 port is listening ...");
});

Start the server:


1.2 Ajax Get request

code:

AjaxDemo.html Script label

    <!--Get button element-->
    const btn = document.getElementsByTagName('button')[0];
    const result = document.getElementById('result');

    // Binding event
    btn.onclick = () => {
    
        // 1. Create objects
        const xhr = new XMLHttpRequest();
        // 2. Initialize the request method and URL
        xhr.open('GET', 'http://127.0.0.1:8000/server');
        // 3. Send
        xhr.send();
        // 4. The results returned by the event binding processing service side
        // on when ....
        // ReadyState is the attribute in the XHR object, indicating status 0 1 2 3 4
        // Change change
        xhr.onreadystatechange = () => {
    
            // Judgment (the server returns all the results)
            if (xhr.readyState === 4) {
    
                // Judgment response status codes 200 404 403 401 500
                // 2xx Successful
                // Treatment results Line heads
                // response
            if (xhr.status >= 200 && xhr.status < 300) {
    
                console.log("Status code:" + xhr.status);// The status code of the response
                console.log("xhr.statusText: " + xhr.statusText);// The status string of the response
                console.log("Response head:" + xhr.getAllResponseHeaders());// All the response header
                console.log("response body:" + xhr.response);// response body
                // Set the text of Result
                result.innerText = xhr.response;
}
            }
        }
    }

Instructions:

const xhr = new xmlhttpRequest ();

See the famous meaning: XHR is the abbreviation of XMLHTTPREQUEST, and there is XHR in the console of the tourist (indicating AJAX please request)
在这里插入图片描述

How to judge the server back to all the results? => ReadyState is the attribute in the XHR object, indicating status 0 1 2 3 4

When the status code is 4, it means that all data has returned.


1.3 Test: We took the result from the server without refreshing

2. Set the request parameter

AjaxDemo.html Script label

    <!--Get button element-->
    const btn = document.getElementsByTagName('button')[0];
    const result = document.getElementById('result');

    // Binding event
    btn.onclick = () => {
    
        // 1. Create objects
        const xhr = new XMLHttpRequest();
        // 2. Initialize the request method and URL
       xhr.open('GET', 'http://127.0.0.1:8000/server?a=100&b=200&c=300');
        // 3. Send
        xhr.send();
        // 4. The results returned by the event binding treatment of the server
        xhr.onreadystatechange = () => {
    
            // Judgment (the server returns all the results)
            if (xhr.readyState === 4) {
    
              if (xhr.status >= 200 && xhr.status < 300) {
    
               // Set the text of Result
                result.innerText = xhr.response;
              }
            }
        }
    }

xhr.open('GET', 'http://127.0.0.1:8000/server?a=100&b=200&c=300');

Note to observe the URL: The carrying of the parameter is added behind the URL? The separation symbol in the form of key = value
在这里插入图片描述



source

Related Posts

MAC skills: how to repairs the copy and paste that cannot be repaired

nlp | Natural language processing -grammar analysis

POJ 2185 Milking Grid

html drop -down menu box small triangle can’t find what to do

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

vue2.0 template Handsome

mysql cursor use template

Mychrome Make a CHROME browser portable version

Create uboot environment variable BIN file

Those Python libraries that have been underestimated, see how many have you used? Wang