将二进制图像中的对象映射到我的彩色图像上 [英] Map objects from my Binary Image onto my colour image

查看:142
本文介绍了将二进制图像中的对象映射到我的彩色图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用bwconcomp函数在二进制图像中查找对象。我知道如何访问numbobjects。我将regionprops用于其他元素。

I've used the bwconcomp function to find objects in my binary image. I know how to access the numbobjects. I use regionprops for other elements.

我理想的目标是将它们的区域映射到彩色图像。因此,我可以在彩色图像上选择每个单独的对象,并在彩色图像上计算事物。我还希望获得MBR每个对象的角点像素。

My ideal goal is the map the area of them to a colour image. So I can select each individual object on the colour image and compute things on the colour image. I also would like to get the corner pixels of each object for a MBR.

如果你能指出我正确的方向来创建蒙版。那将是值得赞赏的:)

If you could point me in the right direction for creating mask. That would be appreciated :)

推荐答案

您可以使用边界框分析执行regionprops。你可以在那里找到没有对象。您还可以获得该对象的左上角坐标和高度和宽度。

You can perform regionprops with bounding box analysis. You can find the no of objects there. You would also be able to get upper left corner co-ordinates and height and width of that object.

如果你没有裁剪原始图像,那么你可以简单地使用相同的坐标来提取你的对象。如果要裁剪,则可以将偏移量添加到左上角,并将原始图像添加到原始图像。

If you are not cropping the original image then you can simply use the same co-ordinates in order to extract your object. If you want to crop, then you can add the offset to the upper-left corner and the same for original image.

这是我的编码示例之一。

Here is one of my coding examples.

clear all;
clc;

%convert image into pixel data
im = imread('abc.jpg');
%convert image to binary with edges only
bw = im2bw(im, 0.1);
%show image
imshow(bw);

%identify various boxes present in the image and also calculate their area
stats = regionprops(bw, 'BoundingBox', 'Area');

j=1;

% m is the maximum area i.e. area of entire image
max = 2819982;
for i=2:length(stats)
    if stats(i).Area ~= 1
        if stats(i).Area <= max

            %this would crop image to perticular box
            ans=imcrop(im, stats(i).BoundingBox);

            % here the image is saved as a new file 
            filename = sprintf('Answer_%d.jpg',j);
            imwrite(ans,filename);

            % j is just an incrementor for filename
            j=j+1;

        end
    end
end

这是我工作的形象: -

Here is the image that i worked on:-

目标是将每个矩形分离为图像。

The goal was to separate each rectangle as image.

这篇关于将二进制图像中的对象映射到我的彩色图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆