I am using python 2.7
我正在使用python 2.7
I have an array of indices created by
我有一个由...创建的索引数组
ids=np.indices((20,20))
ids[0] is filled with all the vertical coordinates and ids1 is filled with all the horizontal coordinates ids has a shape of (2,20,20)
ids [0]填充所有垂直坐标,ids1填充所有水平坐标ids的形状为(2,20,20)
I have a boolean mask of shape (20,20)
我有一个布尔形状的面具(20,20)
I need to have a list of ids that correspond to the ones marked as true in the mask.
我需要有一个id列表,它们与掩码中标记为true的id相对应。
I am trying to do this by mid=ids[:,mask].T which gives me a list of this sort
我试图通过mid = ids [:,mask] .T来做这个,它给了我这种类型的列表
[2,17] [4,6] [1,19] [18,4]
[2,17] [4,6] [1,19] [18,4]
and so on. They are saved in an array called mid
等等。它们保存在一个名为mid的数组中
Then, I need all those coordinates in mid to find the values in another array. Meaning I need
然后,我需要mid中的所有坐标来查找另一个数组中的值。我需要的意思
anotherarray([2,17])
I have not managed to take the list of mid to use them in a fancy indexing way, can someone help me?
我没有设法将mid中的列表用于花哨的索引方式,有人可以帮助我吗?
I have
anotherarray[mid[0],mid[1]]
and it doesnt work. I also have
它不起作用。我也有
anotherarray[tuple(mid)]
and it doesn't work
它不起作用
Edit (read only if you care about context): I wanted to add context to show why I think I need the extra indices. Maybe I don't, that is what I want to fin out to make this efficient.
编辑(只有在关心上下文时才读):我想添加上下文来说明为什么我认为我需要额外的索引。也许我不这样做,这就是我想要的结果,以提高效率。
This is a registration problem, a ver simple one. I have two images. A reference and a floating as seen below. Reference to the left, and floating to the right.
这是一个注册问题,简单的问题。我有两张照片。参考和浮动如下所示。参考左边,并浮动到右边。
The reference image and the floating image are in different coordinate spaces. I have points marked as you can see in the images. I find an affine transformation between each other.
参考图像和浮动图像位于不同的坐标空间中。我在图像中可以看到标记的点。我发现彼此之间有仿射变换。
The region delimited by the line is my region of interest. I send the coordinates of that region in the floating space to the reference space.
该线划定的区域是我感兴趣的区域。我将浮动空间中该区域的坐标发送到参考空间。
There in the reference space, I find what pixels are found inside the region and they become the mask
array, containing the information of both in and outer pixels.
在参考空间中,我发现在区域内找到了哪些像素,它们成为掩模数组,包含内部像素和外部像素的信息。
But I only care about those inside, so I want only the indices of those pixels inside the mask in the reference space and save them using mid=ids[:,mask]
.
但我只关心内部的那些,所以我只想要参考空间中掩码内的那些像素的索引,并使用mid = ids [:,mask]保存它们。
Once I have those points, I transform them back to the floating space, and in those new indices I need to look for the intensity. Those intensities are the ones who will be written back in the reference in their corresponding indices. That is why I think I need to have the indices of those points in both reference and floating space, and the intensities of the image. That other image is the anotherarray
from which I want only the transformed masked pixels.
一旦我有了这些点,我就将它们转换回浮动空间,在那些新指数中我需要寻找强度。这些强度是那些将在相应指数中写回参考文献的强度。这就是为什么我认为我需要在参考和浮动空间中获得这些点的索引,以及图像的强度。另一个图像是另一个图像,我只想要转换的蒙版像素。
So there you go, that is the explanation if you care about it. Thank you for reading and answering.
那么你去吧,如果你关心它就是解释。感谢您阅读和回答。
1 个解决方案