查找图像中的像素索引表明一种情况

詹姆

我有一个包含4个值{3,-3,1,-1}的图像,如图所示 在此处输入图片说明

让我们称其轮廓等于1或-1像素的像素索引。这些像素将创建一个包围黄色(-3)的轮廓。现在,我要查找轮廓中的所有索引像素,以及向内和向外轮廓的填充位置。作为红色,将填充设置为1,因此,这些像素的索引包括轮廓{1,-1}中的像素和作为红色的填充索引。在该任务中,我想找到所有像素索引。如何在Matlab代码中实现该想法。这是我在轮廓中找到索引的代码

%% Let define the image I
idx=find(I==1|I==-1);
padding=1;
%%Continue

Update: My expected result as the above figure in white region. Hence, the indices are such as 13,14,15,..21,24,...

UPDATE

Firstly, thank Andrew and Rayryeng for your answer. I would like to extedn my problem. As the above description, the contour is created by {1,-1}. Now, I want to ignore 1 and -1, so the image I only has {3,-3}. And I defined the contour is pixel in the edge of {3,-3} such as figure. Keep the same idea of padding and pixel index. How to find the indices of pixels in contour and near contour (call narrow band of contour)(expected result is white color) 在此处输入图片说明

andrew

您在正确的轨道上并不太难。如果您拥有图像处理工具箱,我建议您看一下形态运算符特别是您要使用我的代码体现您需要的所有详细信息。

%rather than using find, we create a binary mask. Its not the indicies of
%the matching elements as find gives. its is 1/true if the value matches the
%criteria, and 0/false otherwise.
mask = (im=1 | im=-1);

%create a 3x3 rectangle structuring element. We use a 3x3 because we want
%to expand the image by one pixel. basically the structring element (Strel)
%is our kernal, if you know image processing this is the same thing. 
%a = [0 0 0 0;
%     0 1 1 1;
%     0 1 1 1;
%     0 1 1 1];
%our kernal is center at 2,2 (for this example) which are these elements
%     0 0 0  of a  think a(1:3,1:3) now what the dialate operation
%     0 1 1  says is, if the majority of these pixels are ones... they
%     0 1 1  should probabaly all be ones so all those 0s will become ones
%the size of the kernal 3x3 ensures we are only growing our image one
%pixel, hope that makes sense    
se = strel('square',3);

%now we dilate, or 'expand' our mask with our structuring element
expanded_mask = imdilate(mask,se);

%if you still want the indicies you can use find on our expanded mask
idx = find(expanded_mask==1);

编辑:没有形态学操作/图像处理工具箱此方法使用大量的for循环,因此它不是最快的,并且不执行错误检查,但它可以工作。我的膨胀函数说,如果大多数像素都是像素,那就把它们都变成像素。

function expanded_mask=DilateBinaryImage(bin_im, kernal_size)
    [max_row,max_col] = size(bin_im);

    %since we are opening the mask (only adding 1s), we can start off with the
    %same values of the mask, and simply add extra 1's as needed
    expanded_mask = bin_im;

    %we don't want to go off the edge of our image with this kernal
    %so we offset it a bit
    kern_padding = floor(kernal_size/2);

    %this ignores the edges
    for (curr_row=kern_padding+1:1:max_row - kern_padding)
       for (curr_col=kern_padding+1:1:max_col - kern_padding)
          %we do 2 sums, one for rows, one for columns
          num_ones = sum(sum(bin_im(curr_row-kern_padding:curr_row+kern_padding,curr_col-kern_padding:curr_col+kern_padding)));

          %if the majority of vlaues are 1, we use floor to help with corner
          %cases
          if (num_ones >= floor((kernal_size*kernal_size)/2))
              %make all the values one
              expanded_mask(curr_row-kern_padding:curr_row+kern_padding,curr_col-kern_padding:curr_col+kern_padding) = 1;
          end
       end
    end


end

然后这样称呼它

kernal_size= 3;
mask = (I==1 | I==-1);
expanded_mask = DilateBinaryImage(mask, kernal_size);
idx = find(expanded_mask==1);

我的膨胀函数在二进制图像的边缘不起作用。它只是复制它们。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我需要一种快速的方法来遍历Python中图像/堆栈的像素

来自分类Dev

有没有一种方法可以提取索引颜色位图(C#)中像素的索引?

来自分类Dev

Python:哪一种是在Pandas数据框中查找索引的快速方法?

来自分类Dev

将RGB图像中特定颜色的像素更改为另一种颜色Matlab

来自分类Dev

Python Imaging Library-将一种像素合并为另一种图像

来自分类Dev

有没有一种方法可以将图像逐像素转换为黑白像素?

来自分类Dev

KNN-预测python中的一种情况

来自分类Dev

默认情况=最后一种情况

来自分类Dev

从RGB图像中删除一种颜色

来自分类Dev

有没有一种方法可以遍历一系列图像来查找pygame中单击的图像?

来自分类Dev

一种在Flutter中调用绘画后保存在画布上绘制的像素的方法吗?

来自分类Dev

查找字符串是否是python中某个字符串的子字符串:一种特殊情况

来自分类Dev

查找字符串是否是python中某个字符串的子字符串:一种特殊情况

来自分类Dev

如何从一种特定颜色读取像素的位置?

来自分类Dev

一种去除接近像素的更快方法

来自分类Dev

查找RGB图像中的裁剪像素

来自分类Dev

查找图像中红色像素的坐标

来自分类Dev

在图像中查找某些像素值

来自分类Dev

查找鱼眼图像中的像素位移

来自分类Dev

Python:查找图像中黑色像素的数量

来自分类Dev

使用 goto 从一种情况下降到另一种情况

来自分类Dev

宏作为 switch-case 中的一种情况在 c 中不起作用

来自分类Dev

有没有一种方法可以直接访问Android中显示器的像素颜色?

来自分类Dev

有没有一种算法可以复制2D数组中存储的相邻像素值?

来自分类Dev

有没有一种方法可以直接访问Android中显示器像素的颜色?

来自分类Dev

继承是Go中嵌入式结构的一种特殊情况吗?

来自分类Dev

了解objc中块内存管理的一种极端情况

来自分类Dev

用JavaScript中的常规exp验证数字在一种情况下不起作用

来自分类Dev

垂直居中但嵌套在锚定和跨度中的另一种情况

Related 相关文章

  1. 1

    我需要一种快速的方法来遍历Python中图像/堆栈的像素

  2. 2

    有没有一种方法可以提取索引颜色位图(C#)中像素的索引?

  3. 3

    Python:哪一种是在Pandas数据框中查找索引的快速方法?

  4. 4

    将RGB图像中特定颜色的像素更改为另一种颜色Matlab

  5. 5

    Python Imaging Library-将一种像素合并为另一种图像

  6. 6

    有没有一种方法可以将图像逐像素转换为黑白像素?

  7. 7

    KNN-预测python中的一种情况

  8. 8

    默认情况=最后一种情况

  9. 9

    从RGB图像中删除一种颜色

  10. 10

    有没有一种方法可以遍历一系列图像来查找pygame中单击的图像?

  11. 11

    一种在Flutter中调用绘画后保存在画布上绘制的像素的方法吗?

  12. 12

    查找字符串是否是python中某个字符串的子字符串:一种特殊情况

  13. 13

    查找字符串是否是python中某个字符串的子字符串:一种特殊情况

  14. 14

    如何从一种特定颜色读取像素的位置?

  15. 15

    一种去除接近像素的更快方法

  16. 16

    查找RGB图像中的裁剪像素

  17. 17

    查找图像中红色像素的坐标

  18. 18

    在图像中查找某些像素值

  19. 19

    查找鱼眼图像中的像素位移

  20. 20

    Python:查找图像中黑色像素的数量

  21. 21

    使用 goto 从一种情况下降到另一种情况

  22. 22

    宏作为 switch-case 中的一种情况在 c 中不起作用

  23. 23

    有没有一种方法可以直接访问Android中显示器的像素颜色?

  24. 24

    有没有一种算法可以复制2D数组中存储的相邻像素值?

  25. 25

    有没有一种方法可以直接访问Android中显示器像素的颜色?

  26. 26

    继承是Go中嵌入式结构的一种特殊情况吗?

  27. 27

    了解objc中块内存管理的一种极端情况

  28. 28

    用JavaScript中的常规exp验证数字在一种情况下不起作用

  29. 29

    垂直居中但嵌套在锚定和跨度中的另一种情况

热门标签

归档