Compiling features from regionprops with its filename

1 回表示 (過去 30 日間)
Lim
Lim 2015 年 7 月 30 日
コメント済み: Walter Roberson 2015 年 7 月 30 日
I am working on extracting features on my images and compiling the features into one file. I want to put the file name under that file too but it only display the name and it's in 'char'.
My code:
files = dir('*_cell.bmp'); %the folder has 5 images with this extension
[m1 n1] = size(files);
Feature = [];
for i = 1:m1
x1 = files(i).name;
[path, name, extension] = fileparts(x1);
OriginalImage = imread(x1);
Blue = OriginalImage(:,:,3);
binaryImage = Blue > 0.1;
CellMeasure = regionprops(binaryImage,'all');
CellArea = CellMeasure.Area;
Feature = [Feature; name CellArea];
end
Output: - on the Workspace, >> Feature 5x10 char
>> Feature
Feature =
0201_cell
0205_cell
0206_cell
0401_cell
4101_cell
Please help.

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 30 日
Before:
Feature = cell(m1, 2);
In the loop:
Feature(i,:) = {name CellArea};

その他の回答 (1 件)

Lim
Lim 2015 年 7 月 30 日
It works! Thanks Walter! What if I have more features? I do this:
files = dir('*_cell.bmp');
[m1 n1] = size(files);
Feature = cell(m1,2);
for i = 1:m1
x1 = files(i).name;
[path, name, extension] = fileparts(x1);
OriginalImage = imread(x1);
Blue = OriginalImage(:,:,3);
binaryImage = Blue > 0.1;
CellMeasure = regionprops(binaryImage,'all');
CellArea = CellMeasure.Area;
CellPerimeter = CellMeasure.Perimeter;
ShapeFeat = [CellArea CellPerimeter];
Red = OriginalImage(:,:,1);
Green = OriginalImage(:,:,2);
RMean = mean(Red(:));
GMean = mean(Green(:));
BMean = mean(Blue(:));
ColorFeat = [RMean GMean BMean];
AllFeat = [ShapeFeat ColorFeat];
Feature(i,:) = {name AllFeat};
end
...and it returns
>>Feature
Feature =
'001_cell' [1x16 double]
'002_cell' [1x16 double]
'003_cell' [1x16 double]
How do I expand all the features (in this case, 16) under 'Feature' so that I can save it in an excel file later?
filename = 'M3_Cell.xlsx';
xlswrite(filename,Feature);
  1 件のコメント
Walter Roberson
Walter Roberson 2015 年 7 月 30 日
Feature(i,:) = [name num2cell(AllFeat)];
This assumes that AllFeat will be strictly a row vector of numeric values. If that is not the case then you would have to construct, for example,
{name RMean CellMeasure.PixelIDList}

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

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by