How to extract feature from multiple image?

조회 수: 4 (최근 30일)
Farhan Abdul Wahab
Farhan Abdul Wahab 2016년 12월 23일
댓글: Image Analyst 2016년 12월 24일
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
KSSV
KSSV 2016년 12월 23일
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 2016년 12월 23일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 12월 23일
편집: Image Analyst 2016년 12월 24일
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
Farhan Abdul Wahab
Farhan Abdul Wahab 2016년 12월 24일
편집: Farhan Abdul Wahab 2016년 12월 24일
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 2016년 12월 24일
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;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by