Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何使用'regionprops'显示多个连接组件中的单个组件`_Matlab_Image Processing_Binary_Connected Components - Fatal编程技术网

Matlab 如何使用'regionprops'显示多个连接组件中的单个组件`

Matlab 如何使用'regionprops'显示多个连接组件中的单个组件`,matlab,image-processing,binary,connected-components,Matlab,Image Processing,Binary,Connected Components,在MATLAB中使用函数regionprops时,可以选择提取每个连接组件的二进制图像。二值图像的大小减小为连接组件的大小。我不希望二值图像的大小减小。我希望二值图像的大小保持其原始大小,同时仅在原始图像大小的相应位置显示选定的连接组件。如何提取原始图像大小的连接组件?只需创建一个与原始图像大小相同的空白图像,而不是提取每个blob的图像,通过对每个BLB参考原始图像提取实际像素位置,然后通过在空白图像中将这些位置设置为二进制真< /代码>填充空白图像。使用regionprops中的PixelI

在MATLAB中使用函数
regionprops
时,可以选择提取每个连接组件的二进制图像。二值图像的大小减小为连接组件的大小。我不希望二值图像的大小减小。我希望二值图像的大小保持其原始大小,同时仅在原始图像大小的相应位置显示选定的连接组件。如何提取原始图像大小的连接组件?

只需创建一个与原始图像大小相同的空白图像,而不是提取每个blob的图像,通过对每个BLB参考原始图像提取实际像素位置,然后通过在空白图像中将这些位置设置为二进制<代码>真< /代码>填充空白图像。使用
regionprops
中的
PixelIdxList
属性获取所需组件的列主位置,然后使用这些属性将这些相同位置的输出图像设置为
true

假设您的
regionprops
结构存储在
S
中,并且您希望提取
k
th分量,并且原始图像存储在
A
中,请执行以下操作:

% Allocate blank image
out = false(size(A, 1), size(A, 2));

% Run regionprops
S = regionprops(A, 'PixelIdxList');

% Determine which object to extract
k = ...; % Fill in ID here

% Obtain the indices
idx = S(k).PixelIdxList;

% Create the mask to be the same size as the original image
out(idx) = true;

imshow(out); % Show the final mask
如果您有多个对象,并且希望创建此遮罩,即每个对象的图像原始大小,则可以使用
for
循环为您执行此操作:

% Run regionprops
S = regionprops(A, 'PixelIdxList');

% For each blob... 
for k = 1 : numel(S)
    out = false(size(A, 1), size(A, 2)); % Allocate blank image

    % Extract out the kth object's indices
    idx = S(k).PixelIdxList;

    % Create the mask
    out(idx) = true;

    % Do your processing with out ...
    % ...
end 

只需创建一个与原始图像大小相同的空白图像,而不是提取每一个BLB的图像,提取每个像素的原始图像的实际像素位置,然后在空白图像中将这些位置设置为二进制<代码>真< /COD>填充空白图像。使用

regionprops
中的
PixelIdxList
属性获取所需组件的列主位置,然后使用这些属性将这些相同位置的输出图像设置为
true

假设您的
regionprops
结构存储在
S
中,并且您希望提取
k
th分量,并且原始图像存储在
A
中,请执行以下操作:

% Allocate blank image
out = false(size(A, 1), size(A, 2));

% Run regionprops
S = regionprops(A, 'PixelIdxList');

% Determine which object to extract
k = ...; % Fill in ID here

% Obtain the indices
idx = S(k).PixelIdxList;

% Create the mask to be the same size as the original image
out(idx) = true;

imshow(out); % Show the final mask
如果您有多个对象,并且希望创建此遮罩,即每个对象的图像原始大小,则可以使用
for
循环为您执行此操作:

% Run regionprops
S = regionprops(A, 'PixelIdxList');

% For each blob... 
for k = 1 : numel(S)
    out = false(size(A, 1), size(A, 2)); % Allocate blank image

    % Extract out the kth object's indices
    idx = S(k).PixelIdxList;

    % Create the mask
    out(idx) = true;

    % Do your processing with out ...
    % ...
end