久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 久久i| 国产精品国产成人国产三级 | 中国美女一级黄色片 | 91精品国产综合久久小仙女图片 | 国产女人第一次做爰毛片 | 精品久久久久久 | 日本a级大片 | 国产成人精品免费视频 | 久久久综合久久 | 国产一区在线视频 | 99精品视频免费在线观看 | av中文字幕在线播放 | 亚洲综合在线一区二区 | 亚洲精品久久久9婷婷中文字幕 | 亚洲成人综合在线 | 中文字幕国产视频 | 亚洲欧美日韩精品久久亚洲区 | 少妇一级淫片免费播放 | 国产精品亚洲精品 | 国产精品久久久久久久久久三级 | 黄片毛片在线观看 | 国产精品久久av | 亚洲国产一区二区视频 | 99精品久久久久久久 | 亚洲高清在线观看 | 国产精品一区二区三区在线 | 日韩精品 电影一区 亚洲 | 99re在线视频精品 | 91免费在线| 中文字幕97 | 久久国产精品-国产精品 | 夜夜爽99久久国产综合精品女不卡 | 天堂av免费观看 | 国产精品美女久久久久久不卡 | 在线视频中文字幕 | 91夜色在线观看 | 久久噜噜噜精品国产亚洲综合 | 精品无码久久久久久国产 | 日韩欧美网 | 久久欧美精品 | 一区二区三区四区在线视频 |