How to extract feature from multiple image?

4 Ansichten (letzte 30 Tage)
Farhan Abdul Wahab
Farhan Abdul Wahab am 23 Dez. 2016
Kommentiert: Image Analyst am 24 Dez. 2016
The aim of the outcome; which to display the result is similar to this:
but instead I would like to fetch the feature from other images, where only one object inside each image.
1. Read image from file - successful
2. Convert RGB to gray - successful
3. Convert Gray to Binary - successful
4. Extract the feature for each image - failed. - It supposed to return Area for each 10 images, somehow it only return 1 value.
  2 Kommentare
KSSV
KSSV am 23 Dez. 2016
Post your code, so that we can check and find out why you are getting only one return value.
Farhan Abdul Wahab
Farhan Abdul Wahab am 23 Dez. 2016
Here's the code:
close all;
clear all;
clc;
%(1)-- read all images from folder
path_data_train=strrep(cd,...
'Classification_Shape','ShapeImage\BottleTraining');
% data training of Good (jn)
lots_of_data_train_jn=2;
% data training of Bad (jl)
lots_of_data_train_jl=1;
% initialization of matrix dataset
n=lots_of_data_train_jn+lots_of_data_train_jl;
for i=1:n
if(i<=lots_of_data_train_jn)
% reading each file of Good
filename=strcat(path_data_train,'\','Good',...
num2str(i),'.jpg');
class{i}='Good';
else
% reading each file of Bad
filename=strcat(path_data_train,'\','Bad',...
num2str(i-(lots_of_data_train_jn)),'.jpg');
class{i}='Reject';
end
I = imread (filename);
if(size(I,3)==4) % resize image
I(:,:,1)=[]; % convert to I = [MxNx3]
end
%figure, imshow (I);
% (2)-- Convert data to gray
I_gray=rgb2gray (I);
%figure,imshow(I_gray);
% (3)-- Create inverted binary image
%I_biner=zeros(size(I_gray,1),size(I_gray,2));
%I_biner(find(I_gray<255))=1;
I_biner = im2bw (I_gray, 254/255);
I_biner = bwareaopen (I_biner, 5); % remove small region less than 5pixels of binary image
% I_biner = imfill(I_biner, 'holes');
%figure, imshow(I_biner);
% create max filter image from binary image
%windowing_size must be valued an odd number >=3
windowing_size=5;
max_filter_I_biner=Function_MaxFilterBiner_(I_biner,windowing_size);
figure, imshow(max_filter_I_biner);
% draw boundaries line
hold on;
boundaries = bwboundaries(max_filter_I_biner);
numberOfBoundaries = size(boundaries, 1);
for i = 1 : numberOfBoundaries
thisBoundary = boundaries{i};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
Measurements = regionprops(max_filter_I_biner, 'Area');
theArea = [Measurements.Area]
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 23 Dez. 2016
Bearbeitet: Image Analyst am 24 Dez. 2016
It looks like there are two problem. You are using the loop index "i" inside another, outer loop, which also has the same loop index. Not a wise choice. And it looks like the outer i, which should be renamed to something like imageNumber is the image number but your areas are just for the current image. So put all the areas into a cell. It needs to be a cell because different areas can have different numbers of regions.
theArea{imageNumber} = [Measurements.Area]
By the way, in the MATLAB editor, type control-a control-i to fix up your indenting before you paste it here. It will make your code easier to follow.
  2 Kommentare
Farhan Abdul Wahab
Farhan Abdul Wahab am 24 Dez. 2016
Bearbeitet: Farhan Abdul Wahab am 24 Dez. 2016
Thank you for the looping correction. It works. Now I have the Area quantity equivalent to image quantity. Somehow I'm not clear on your statement of:
" So put all the areas into a cell. It needs to be a cell because different areas can have different numbers of regions."
What does it mean, and how to do it? By using this?
theArea(imageNumber) = [Measurements.Area]
Below is my binary image for Area calculation.
Image Analyst
Image Analyst am 24 Dez. 2016
Because the number of areas might vary from image to image, use a cell array and braces:
theArea{imageNumber} = [Measurements.Area]
If you're going to have one blob always, like if you use bwareafilt(binaryImage, 1), then you can use a simple numerical array with parentheses:
theArea(imageNumber) = Measurements.Area;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by