计算图像上两点之间的像素 [英] Calculate pixels between two points on a image

查看:272
本文介绍了计算图像上两点之间的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原来我不解释什么是我想要做的非常好,所以我打算再重新写的整个问题,并添加图形,以帮助解释。

Turns out I am not explaining what I want to do very well so I am going to re-write the whole question again and add graphics to assist in the explanation.

我设计为Android / iPhone的应用程序。我已经设计了一个算法,它已经,但我坚持就下单。什么我的目标做的是地方的图像上的两条水平线(采取由iPhone /机器人的任何图像,只是一个图像),然后计算什么像素行碱液上,以再计算它们之间的像素数。 即 拿这个图片:

I am designing an app for android/iPhone. I have designed one algorithm for it already, but am stuck on the next one. What I am aiming to do is place two horizontal lines on an image (any image, just a picture taken by the iPhone/android) and then calculate what pixel the lines lye on, to then calculate the number of pixels between them. I.e. Take this image:

http://i.stack.imgur.com/41vS1.png

那么任何地方的图像上两条水平线,像这样:

Then place two horizontal lines anywhere on the image, like so:

http://i.stack.imgur.com/ne4tV.png

我要计算为y的值,或有多少垂直像素的两条线之间。要做到这一点,我必须知道什么是像素两行碱液上。 假定水平线条都只有1个像素的高度那么我使用什么工作像素的图像中的线位于。即什么是y截距(表达式y = mx + c)中,或c的值,在每个水平线的。 为了解释什么,我还指,让我们假设一个图像是一个曲线图。每个像素等于1的值,所以对于具有1920x2560的分辨率的图象的Y轴的最大值将是1920和x轴的最大将是2560如何将设计一个算法来计算什么截距两条线是什么?

What I want to calculate is the value of y, or how many vertical pixels are between the two lines. To do this I must know what pixel the two lines lye on. Assuming that the horizontal lines are both only 1 pixel in height what would I use to work out what pixel in the image the line lies on. I.e. what is the value of the y-intercept(y=mx+c), or c, on each of the horizontal lines. To explain what I mean further, lets assume that an image is a graph. Each pixel equals a value of 1, so for an image with a resolution of 1920x2560 the maximum value of the y-axis would be 1920 and the maximum of the x-axis would be 2560. How would I design an algorithm to calculate what the y-intercept of both lines are?

推荐答案

两个点(Pythagora)之间的距离:

Distance between two points (Pythagora):

dx = x1 - x2;
dy = y1 - y2;

dist = sqrt (dx*dx + dy*dy);

两条水平线之间的距离:

Distance between two horizontal lines:

d = y1 - y2;

如果你的线被定义为 Y1 = K1X + N1 Y2 = k2x + N2 ,然后(他们重水平, K1 2 0),它们之间的距离为 N2 - N1

If your lines are defined as y1 = k1x + n1 and y2 = k2x + n2, then (they're horizontal, k1 and k2 are 0) the distance between them is n2 - n1.

编辑:确定,您编辑您的问题后,它使更多的意义了。但还是:既然你(或用户)的添加行,你的code永远的知道的它们就躺在那里。他们的终点坐标是:

ok, after you edited your question it makes a bit more sense now. But still: since you (or user) is adding the lines, your code always knows where they lie. Their end coordinates would be:

1行:{(0,Y1):( picture.width,Y1)} 线路2:{(0,y2)上:( picture.width,y2)上} 距离:| Y2-Y1 |

line1: {(0,y1):(picture.width,y1)} line2: {(0,y2):(picture.width,y2)} distance: |y2-y1|

因为他们都是水平的,他们ofcourse从来没有穿过。

Since they're both horizontal they ofcourse never cross.

您应该保持在一个适当的空间参考Y1和Y2(从行配售code)。由于您的问题是Android和iOS的答案是:在code那部分将对应于模式在MVC

You should just keep a reference to y1 and y2 (from the line-placing code) in an appropriate space. Since your question is for Android and iOS the answer is: in that part of code that would correspond to model in MVC.

这篇关于计算图像上两点之间的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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