【问题标题】:Finding Circle Boundary Pixels Coordinates and RGB Intensity Values from An RGB Input Image in Matlab在 Matlab 中从 RGB 输入图像中查找圆边界像素坐标和 RGB 强度值
【发布时间】:2015-06-10 06:00:31
【问题描述】:

我想从仅位于给定 RGB 输入图像中指定圆边界上的点获取像素坐标和 RGB 强度值,而不绘制圆并考虑其指定颜色。据我所知,只是在特定点上画圆。有什么帮助吗?谢谢。

yellow = uint8([255 255 0]); 
% Create the shape inserter object.
shapeInserter = vision.ShapeInserter('Shape','Circles','BorderColor','Custom','CustomBorderColor',yellow);
% Read RGB input image.
I = imread('3.jpg'); 
% Define the circle dimensions
x1=80;
y1=80;

circle = int32([x1 y1 3]); %  [x1 y1 radius]

% Draw the circle and display the result.
J = step(shapeInserter, I, circle);
imshow(J);

【问题讨论】:

    标签: image matlab image-processing matlab-cvst


    【解决方案1】:

    您不需要计算机视觉工具箱。只需定义圆的中心坐标和指定的半径,然后结合使用 meshgrid 和逻辑索引来确定 (x,y) 坐标以及沿圆周边的相应 RGB 值。

    类似这样的:

    %// Define parameters
    x1 = 80; y1 = 80;
    radius = 3;
    tol = 0.1;
    
    %// Get dimensions of image
    rows = size(I,1); cols = size(I,2);
    
    %// Define grid of coordinates
    [x,y] = meshgrid(1:cols, 1:rows);
    
    %// Define mask for valid pixels
    mask = ((x - x1).^2 + (y - y1).^2) >= (radius - tol)^2;
    mask = mask & ((x - x1).^2 + (y - y1).^2) <= (radius + tol)^2;
    
    %// Get row and column locations
    col = x(mask); row = y(mask);
    
    %// Get pixel values
    R = I(:,:,1); G = I(:,:,2); B = I(:,:,3);
    red = R(mask); green = G(mask); blue = B(mask);
    

    这些陈述:

    mask = ((x - x1).^2 + (y - y1).^2) >= (radius - tol)^2;
    mask = mask & ((x - x1).^2 + (y - y1).^2) <= (radius + tol)^2;
    

    定义圆的方程:

    (x - x0)^2 + (y - y0)^2 == r^2
    

    中心坐标定义在(x0, y0),半径为r。但是,由于图像中的坐标是离散的,您需要在半径的某个容差范围内获取值。我将此容差设置为 0.1。这个方程定义了圆的边界。因此,我们希望在图像中找到那些允许上述表达式为真的位置。

    完成后,我们可以获取像素沿边界的行和列位置,最后我们可以使用逻辑掩码本身对每个通道进行索引,并为每个通道获取相应的红色、绿色和蓝色像素沿边界定义的位置。


    这是一个半径为 30 的示例,以(100,100) 为中心,行和列分别设置为 300。我们可视化面具的样子。白色表示我们此时采样,黑色表示我们不采样:

    【讨论】:

    • 感谢您的尝试 rayryeng,但您的解决方案在矩形网格中找到点坐标和值,而不是在一个圆圈中。一个圆里应该有很多点坐标。
    • @Dani - 感谢现场。我编辑了帖子。由于离散化,我不得不稍微调整它,但您可以看到它适用于我提供的视觉示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2013-01-10
    • 2014-04-24
    • 2015-05-14
    • 2016-06-21
    • 1970-01-01
    相关资源
    最近更新 更多