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

2個像素之間的距離

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

問題描述

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

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 循環或 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)))

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

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 正方形

現在這樣做:

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]))

現在讓我們做藍色像素:

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]))

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

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模板網!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
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(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 少妇特黄a一区二区三区88av | 国产午夜影院 | 亚洲免费视频一区 | 北条麻妃99精品青青久久主播 | 午夜影院免费体验区 | 久久成人高清视频 | 91久久精品国产91久久性色tv | 精品成人免费一区二区在线播放 | 国产一区二区自拍 | 在线一区视频 | 日日操天天射 | 免费日韩av | 久久久久久久久久久久91 | av大片 | 99国产精品久久久久老师 | 精品久久久久一区二区国产 | 97中文视频 | 狠狠色狠狠色综合系列 | 欧美精品乱码久久久久久按摩 | 日韩精品视频在线 | 一级毛片观看 | 日韩在线观看网站 | 一区二区在线 | www.色婷婷 | 91视频88av| 欧美a在线 | 91在线免费视频 | 亚洲一二三区在线观看 | 99一级毛片 | 亚洲精品高清视频在线观看 | 一区二区精品电影 | 国产麻豆乱码精品一区二区三区 | 九九激情视频 | 日韩久久精品 | 日韩中文字幕一区 | 欧美日韩国产一区二区三区 | 天天射影院 | 三级欧美| 久久免费小视频 | 天堂综合 | 中文字幕视频在线观看 |