使用BoundingBox生成的特定区域

时间:2016-04-21 04:41:51

标签: matlab image-processing image-segmentation

我有n'BoundingBox'区域,'Image'[x, y, Δx, Δy]属性。我将数据(bb1)从特定区域(例如14个)保存到我想要处理的bb1=floor( Ic(14,1).BoundingBox ); I1bb1=I1( bb1(2):bb1(2)+bb1(4)-1 , bb1(1):bb1(1)+bb1(3)-1 ,:); 但首先我需要了解以下代码:

I2=I1bb1.*repmat(  Ic(BB,1).Image , [1 1 3]);

之后,我也想了解下一个来自同一个例子的代码:

Ic

n包含 BoundingBox生成的void decode_tuple(char *buff) { int index = 0; int size; int type; int res = ei_decode_tuple_header(buff, &index, &size); if(res == 0) { cout << "Success" << endl; } else { cout << "Fail" << endl; } for(int i = 0; i < size; ++i) { ei_term term; int res = ei_decode_ei_term(buff, &index, &term); if (res == 0) { cout << "Success" << endl; } else { cout << "Fail" << endl; } cout << "The decoded data is " << term.value << endl; } } 区域

1 个答案:

答案 0 :(得分:0)

你有一个3D变量I1(我想是RGB图像),你希望从中裁剪边界框Ic(14,1).BoundingBox。也就是说,有一个较小的3D数组,对应于图像I1中的边界框内的像素。要做这个裁剪你有这些命令:

bb1=floor( Ic(14,1).BoundingBox );

首先,确保边界框的值[x, y, w, h]是整数而不是子像素,以便您可以使用这些值进行索引。然后,您可以使用边界框索引I1

I1bb1=I1( bb1(2):bb1(2)+bb1(4)-1 , bb1(1):bb1(1)+bb1(3)-1 ,:);

对于I1bb1行,您可以获取bb1(2)y值)到y+w-1的行bb1(2)+bb1(4)-1。从xx+h-1的列相同。

对于第三行代码,您拥有属性Ic(14,1).Image。这个属性是

  

返回与区域边界框大小相同的二进制图像(逻辑)。 on像素对应于区域,所有其他像素都关闭。

现在您希望I2与边界框的大小相同,但边界框中不属于该对象的所有像素都设置为[0 0 0](所有RGB值为零)。因此,您可以将Ic(14,1).Image从2D二进制掩码转换为三个通道的3D掩码:

repmat(  Ic(BB,1).Image , [1 1 3])

最后,你逐元素地增加&#34;膨胀&#34;使用裁剪后的图片I1bb1进行遮罩:

I2=I1bb1.*repmat(  Ic(BB,1).Image , [1 1 3]);

使用稍微更易读的代码可以获得相同的结果:

Ibb1 = imcrop( I1, bb1 ); %// crop a bounding box from image 
I2 = bsxfun( @times, Ibb1, Ic(14,1).Image ); %// no need for repmat