简体   繁体   English

在图像中查找强度相同的项目

[英]Finding items in an image which have the same intensity

How can I find all the points (or the region) in an image which has 3-dimensions in which the first two dimensions show the resolution and the 3rd one shows the density? 如何在具有3维的图像中找到所有点(或区域),其中前两个维显示分辨率,第三个维显示密度? I can use Matlab or Python. 我可以使用Matlab或Python。 I wonder if there is a native function for finding those points that is least computationally expensive. 我想知道是否存在本机函数来查找那些计算成本最低的点。 UPDATE: Imagine I have the following: 更新:假设我有以下内容:

A= [1,2,3; 4,6,6; 7,6,6]
A =

     1     2     3
     4     6     6
     7     6     6

>> B=[7,8,9; 10,11,11; 1, 11,11]

B =

     7     8     9
    10    11    11
     1    11    11

>> C=[0,1,2; 3, 7, 7; 5,7,7]

C =

     0     1     2
     3     7     7
     5     7     7

How can I find the lower square in which all the values of A equal the same all the values of B and all the values of C? 如何找到A的所有值都等于B的所有值和C的所有值的下平方? If this is too much how can I find the lower square in A wherein all the values in A are equal? 如果太多,我如何才能找到A中所有值都相等的A的下平方? *The shown values are the intensity of the image. *显示的值是图像的强度。

UPDATE: tries the provided answer and got this error: 更新:尝试提供的答案并得到以下错误:

>> c=conv2(M,T, 'full');
Warning: CONV2 on values of class UINT8 is obsolete.
         Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead. 
> In uint8/conv2 (line 10) 
Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d real'.

Error in uint8/conv2 (line 17)
y = conv2(varargin{:});

*Also tried convn and it took forever so I just stopped it! *还尝试了convn ,它花了很convn ,所以我才停止了! Basically how to do this for a 2D array as described above? 基本上如上所述,如何对2D阵列执行此操作?

You can use a pair of horizontal and vertical 1D filters such that the horizontal filter has a kernel of [1 -1] while the vertical filter has a kernel of [1; -1] 您可以使用一对水平和垂直一维滤镜,以便水平滤镜的内核为[1 -1]而垂直滤镜的内核为[1; -1] [1; -1] . [1; -1] The effect of this is that it takes both horizontal and vertical pairwise distances for each element in each dimension separately. 这样做的效果是,每个维度中的每个元素分别需要水平和垂直成对距离。 You can then perform image filtering or convolution using these two kernels ensuring that you replicate the borders. 然后,您可以使用这两个内核执行图像过滤或卷积,以确保复制边界。 To be able to find uniform regions, by checking which regions in both results map to 0 between them both, this gives you areas where areas that are uniform over all channels independently. 为了能够找到均匀的区域,通过检查两个结果中的哪个区域在两个区域之间映射为0,可以为您提供在所有通道上独立的区域。

To do this, you would first take the opposite of both filtering results so that uniform regions that would become 0 are now 1 and vice-versa. 为此,您首先要对两个过滤结果进行相反的处理 ,以使将变为0的均匀区域现在为1,反之亦然。 that you perform the logical AND operation on both of these together and then ensure that for each pixel temporally, all of the values are true . 您必须对这两个元素同时执行logical AND操作,然后确保对于每个像素在时间上所有值均为true This would mean that for a spatial location in this image, all values experience the same uniformity as you expect. 这意味着对于此图像中的空间位置,所有值都将达到您期望的相同均匀性。

In MATLAB, assuming you have the Image Processing Toolbox, use imfilter to filter the images, then use all in MATLAB to look temporally after the two filtering results, and then use regionprops to find the coordinates of the regions you seek. 在MATLAB中,假定您具有“图像处理工具箱”,请使用imfilter过滤图像,然后在MATLAB中使用all来临时查看这两个过滤结果,然后使用regionprops查找所需区域的坐标。 So do something like this: 所以做这样的事情:

%# Reproducing your data
A = [1,2,3; 4,6,6; 7,6,6];
B = [7,8,9; 10,11,11; 1, 11,11];
C = [0,1,2; 3, 7, 7; 5,7,7];

%# Create a 3D matrix to allow for efficient filtering
D = cat(3, A, B, C);

%# Filter using the kernels
ker = [1 -1];
ker2 = ker.'; %#
out = imfilter(D, ker, 'replicate');
out2 = imfilter(D, ker2, 'replicate');

%# Find uniform regions
regions = all(~out & ~out2, 3);

%# Determine the locations of the uniform areas
R = regionprops(regions, 'BoundingBox');

%# Round to ensure pixel accuracy and reshape into a matrix
coords = round(reshape([R.BoundingBox], 4, [])).';

coords would be a N x 4 matrix with each row telling the upper-left coordinates of the bounding box origin as well as the width and height of the bounding box. coords是一个N x 4矩阵,每行告诉边界框原点的左上坐标以及边界框的宽度和高度。 The first and second elements in a row are the column and row coordinate while the third and fourth elements are the width and height of the bounding box. 行中的第一和第二元素是列和行的坐标,而第三和第四元素是边界框的宽度和高度。

The regions we have detected can be found in the regions variable. 我们检测到的区域可以在regions变量中找到。 Both of these show: 这两个都显示:

>> regions

regions =

  3×3 logical array

   0   0   0
   0   1   1
   0   1   1

>> coords

coords =

     2     2     2     2

This tells us that we have localised the region of "uniformity" to be the bottom right corner while the coordinates of the top-left corner of the bounding box are row 2, column 2 with a width and height of 2 and 2 respectively. 这告诉我们,我们已经将“均匀性”区域定位为右下角,而边界框的左上角的坐标是第2行,第2列,其宽度和高度分别为2和2。

A possible solution: 可能的解决方案:

A = [1,2,3; 4,6,6; 7,6,6];
B = [7,8,9; 10,11,11; 1, 11,11];
C = [0,1,2; 3, 7, 7; 5,7,7];
%create a 3D array
D = cat(3,A,B,C)
%reshape the 3D array to 2D 
%its columns represent the third dimension
%and its rows represent resolution
E = reshape(D,[],size(D,3));
%third output of the unique function applied row-wise  to the data
%represents the label of each pixel a [m*n, 1] vector created
[~,~,F] = unique(E,'rows');
%reshape the vector to a [m, n] matrix of labels
result = reshape(F, size(D,1), size(D,2));

You can reshape the 3D matrix to a 2D matrix ( E ) that its columns represent the third dimension and its rows represent resolution. 您可以将3D矩阵整形为2D矩阵( E ),其列表示三维尺寸,其行表示分辨率。

Then using unique function you can label the image. 然后,使用unique功能可以标记图像。

We have a 3D matrix: 我们有一个3D矩阵:

A =
     1     2     3
     4     6     6
     7     6     6
B =
     7     8     9
    10    11    11
     1    11    11
C =
     0     1     2
     3     7     7
     5     7     7

When we reshape the 3D matrix to a 2D matrix E we get: 当我们将3D矩阵整形为2D矩阵E我们得到:

E =

    1    7    0
    4   10    3
    7    1    5
    2    8    1
    6   11    7
    6   11    7
    3    9    2
    6   11    7
    6   11    7

So we need to classify the rows base on their values. 因此,我们需要根据行的值对行进行分类。

Unique function is capable of extracting unique rows and assign the same label to rows that are equal to each other. 唯一功能能够提取唯一的行,并将相同的标签分配给彼此相等的行。

Here varible F capture third output of the unique function that is label of each row. 此处,变量F捕获唯一功能的第三条输出,即每行的标签。

F =

   1
   4
   6
   2
   5
   5
   3
   5
   5

that should be reshaped to 2D 应该重塑为2D

result = 结果=

1   2   3
4   5   5
6   5   5

so each region has different label. 因此每个区域都有不同的标签。

If you want to segment distinct regions(based on both their values and their spatial positions) you need to do labeling the image in a loop 如果要分割不同的区域(基于它们的值和空间位置),则需要在循环中标记图像

numcolors = max(F);
N = 0;
segment = zeros(size(result));
for c = 1 : numcolors
    [label,n] = bwlabel(result==c);
    segment = segment +label + logical(label)*N;
    N = N + n;
end

So here you need to mark disconnected regions that have the same values with different labels. 因此,这里需要用不同的标签标记具有相同值的断开连接的区域。 since MATLAB doesn't have functions for gray segmentation You can use bwlabel function multiple times to do segmentation and add result of the previous iteration to result of current iteration. 由于MATLAB没有灰色分割功能,因此可以多次使用bwlabel函数进行分割,并将上一次迭代的结果添加到当前迭代的结果中。 segment variable contains the segmentd image. segment变量包含分割的图像。

*Note: this result obtained from GNU Octave that its labeling is different from MATLAB. *注意:此结果是从GNU Octave获得的,其标签不同于MATLAB。 if You use unique(E,'rows','last'); 如果您使用unique(E,'rows','last'); result of MATLAB and Octave will be the same. MATLAB和Octave的结果相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本的效率(找到一对具有相同余数的整数) - Efficiency of the script (finding a pair of integers which have the same remainder) 脚本的复杂性(找到一对具有相同余数的整数) - Complexity of the script (finding a pair of integers which have the same remainder in modulo) 图像轮廓强度 - Image profile intensity 如何计算python中同一图像内两个不同区域的平均像素强度差? - How to calculate the average pixel intensity difference for two different regions within the same image in python? 从列表中提取与包含在第三个列表中的另一个列表的项具有相同索引的值 - Extract values from a list that have the same indices as the items of another list which are contained in a third list 从同一个列表中查找项目对的数量? - Finding number of pairs of items from same list? 什么是图像处理中的强度转换? - What is intensity conversion in image processing? 我有一个矩阵,其中每个元素都是 label 和一个值。 我该如何表示它,以便 label 给出颜色和强度值? - I have a matrix in which each element is a label and a value. How can I represent it so that the label gives the color and the value the intensity? 在Selenium中查找具有相同html属性的元素 - finding elements that have same html attributes in Selenium 检查csv文件是否具有相同的项目 - Checking if csv files have same items
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM