Knn Classify using to classify similar images

4 views (last 30 days)
Hello All,
I'd like to ask if someone can help me to solve a problem that i'm having with one of my project.
I'm trying to classify different images using knn as algorithm, my real goal is analyse a lung x-ray(sample) and classify sample data based on my database (training) into healthy lung, cancer lung, etc (groups) but just to simplify the understanding i'll use simple images.
I have three 100x100 pixels images to use as 'training' that are: red.jpg,green.jpg and blue.jpg
And as my sample images i have another three 100x100 pixels images that are: pink.jpg,aqua.jpg and light_green.jpg
and as a group, [1,2,3] (RED,GREEN,BLUE) to use.
Here is my code:
>> red = imread('images/red.jpg');
>> green = imread('images/green.jpg');
>> blue = imread('images/blue.jpg');
>> pink = imread('images/pink.jpg');
>> aqua = imread('images/aqua.jpg');
>> light_green = imread('images/light_green.jpg');
>> training = [red,green,blue];
>> sample = [aqua,pink,light_green];
>> group = [1,2,3];
But if i try to use the knn classify here i got this error:
Error using knnclassify (line 91)
The length of GROUP must equal the number of rows in TRAINING.
My images sizes are:
>> size(red),size(blue),size(green),size(pink),size(aqua),size(light_green);
ans =
100 100 3
ans =
100 100 3
ans =
100 100 3
ans =
100 100 3
ans =
100 100 3
And the sizes of parameters to knn classify are:
>> size(training),size(sample),size(group)
ans =
100 300 3
ans =
100 300 3
ans =
1 3
But on this example i just have 3 groups, RED (1), GREEN (2) and BLUE (3) how can my group rows be the same as my training rows?
Thank you

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!