久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

2個像素之間的距離

Distance between 2 pixels(2個像素之間的距離)
本文介紹了2個像素之間的距離的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

來自軟件開發(fā),我是圖像處理的新手.我嘗試獲取形狀為 (100, 100, 3) 的 numpy 數(shù)組的圖像中兩個像素之間的距離.

Coming from software development, i'm new to image processing. I try to get the distance between two pixels in an image that is a numpy array of shape (100, 100, 3).

例如,我想找到圖像中像素藍色 (0, 0, 255) 和像素紅色 (255, 0, 0) 之間的距離,我嘗試使用 for 循環(huán)或 np.where() ...但沒有成功.距離可能是圖像中兩個索引之間的某種差異(這些顏色的像素可能更多,因此至少在圖像中第一次遇到)

For example i want to find the distance between a pixel blue (0, 0, 255) and a pixel red (255, 0, 0) in the image, I tried with a for loop or np.where() ... but no success. The distance could be the some kind of difference between the two indexes in the image (possibility that there is more pixels of these colors so at least the first met in the image)

知道怎么做嗎?

我正在像這樣捕獲部分屏幕:

I'm capturing part of my screen like that:

screen = np.array(pyautogui.screenshot(region=(80,120,100,100)))

現(xiàn)在我想在圖像中找到藍色的像素和紅色的像素以及它們之間的距離

Now i want to find the pixel(s) of color blue and the pixel(s) of color red and the distance between them in the image

推薦答案

讓我們從測試圖像開始.它是 400x300 像素的灰色(192),帶有:

Let's start with a test image. It is 400x300 pixels of gray(192), with:

  • 20,10 處的紅色 3x3 正方形,
  • 300,200 處的藍色 3x3 正方形

現(xiàn)在這樣做:

import numpy as np
import PIL
import math

# Load image and ensure RGB - just in case palettised
im=Image.open("a.png").convert("RGB")

# Make numpy array from image
npimage=np.array(im)

# Describe what a single red pixel looks like
red=np.array([255,0,0],dtype=np.uint8)

# Find [x,y] coordinates of all red pixels
reds=np.where(np.all((npimage==red),axis=-1))

這給出了:

(array([10, 10, 10, 11, 11, 11, 12, 12, 12]),
 array([20, 21, 22, 20, 21, 22, 20, 21, 22]))

現(xiàn)在讓我們做藍色像素:

Now let's do the blue pixels:

# Describe what a single blue pixel looks like
blue=np.array([0,0,255],dtype=np.uint8)

# Find [x,y] coordinates of all blue pixels
blues=np.where(np.all((npimage==blue),axis=-1))

這給出了:

(array([200, 200, 200, 201, 201, 201, 202, 202, 202]),
 array([300, 301, 302, 300, 301, 302, 300, 301, 302]))

所以現(xiàn)在我們需要從第一個紅色像素到第一個藍色像素的距離

So now we need the distance from the first red to the first blue pixel

dx2 = (blues[0][0]-reds[0][0])**2          # (200-10)^2
dy2 = (blues[1][0]-reds[1][0])**2          # (300-20)^2
distance = math.sqrt(dx2 + dy2)

這篇關于2個像素之間的距離的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲激精日韩激精欧美精品 | 国产一区二区三区四区 | 在线观看你懂的网站 | 毛片免费看的 | 超碰在线人人干 | 免费毛片在线 | 激情久久网| 青青艹在线视频 | 日韩精品无码一区二区三区 | 日本中出视频 | www.色.com| 黄色大片免费看 | 久久久久亚洲国产| 久久精品99 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 不卡在线视频 | 久久伊人在 | 日韩在线免费视频 | 黄在线 | 亚洲欧美日韩精品 | 精品一区国产 | 欧美视频三级 | 天天久久| 国产精品色 | 中文在线视频观看 | 亚洲成人精品 | 亚洲一区久久 | 亚洲视频一区在线观看 | 97精品国产97久久久久久免费 | 免费久久网 | 国内精品久久精品 | www.久久国产精品 | 欧美日高清 | 日韩精品一区中文字幕 | 日韩av三区| 成人av免费网站 | 国产一二三区免费视频 | 精品久久国产老人久久综合 | 最新国产视频 | 亚洲综合中文字幕在线观看 | 欧美黑人体内she精在线观看 |