归一化图像的坐标 [英] Normalize coordinates of an image

查看:1037
本文介绍了归一化图像的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python中创建一个对象检测程序.输出应该是要分析的图片的文件名,加上对象中心的标准化坐标".

I am trying to create an object detection program in Python. The output should be the filename of the picture being analyzed, plus the "normalized coordinates" of the the object center.

每个图像都应按如下所示进行归一化:

Each image should be normalized as follows:

左上角=(0,0),左下角=(0,1),右上角=(1,0),右下角=(1,1)

Top left = (0,0), Bottom left = (0,1), Top right = (1,0), Bottom right = (1,1)

关于如何标准化每个图像坐标的任何建议或建议?

Any advice or suggestions on how I can normalize the coordinates of each image?

推荐答案

此简单功能可以完成工作:

This simple function would get the job done:

def normalize_coordinates(row_i, col_j, img):
    num_rows, num_cols = img.shape[:2]
    x = col_j/(num_cols - 1.)
    y = row_i/(num_rows - 1.)
    return x, y

演示

from skimage import io
from numpy import random

random.seed(42)
img = io.imread('https://i.stack.imgur.com/94l13.jpg')
row_i = random.randint(0, img.shape[0]) 
col_j = random.randint(0, img.shape[1]) 
x, y = normalize_coordinates(row_i, col_j, img)

print 'row = %d, column = %d  >>>  x = %.2f, y = %.2f' % (row_i, col_j, x, y) 

输出:

row = 102, column = 435  >>>  x = 0.71, y = 0.25

这篇关于归一化图像的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆