フィルターのクリア

how to process images with different sizes for classification?

2 ビュー (過去 30 日間)
arun
arun 2016 年 10 月 24 日
コメント済み: Image Analyst 2016 年 10 月 24 日
I've the following code for the image size (row = 320; col = 240;)
But i'm having images with variable sizes (116x110),(134x125), which need to be processed
function y = bounding_box(img)
[row col] = size(img);
top = 0;
bottom = 0;
left = 0;
right = 0;
for i = 1:row
if sum(img(i,:)) > 0
top = i;
break
end
end
for i = row:(-1):1
if sum(img(i,:)) > 0
bottom = i;
break
end
end
for i = 1:col
if sum(img(:,i)) > 0
left = i;
break
end
end
for i = col:(-1):1
if sum(img(:,i)) > 0
right = i;
break
end
end
y = img(top:bottom, left:right);

回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 24 日
Why not simply ask regionprops() to give you the bounding box?
  2 件のコメント
arun
arun 2016 年 10 月 24 日
can you give me an example code for that?
Image Analyst
Image Analyst 2016 年 10 月 24 日
How many blobs do you have? And if you have more than 1, do you want the bounding box of each one, or the bounding box of all the individual bounding boxes. In short, it's
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'BoundingBox');
props is a structure array with measurements, like bounding box, for each region.
See a full example in my Image Segmentation Tutorial in my File Exchange

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by