Current location - Health Preservation Learning Network - Slimming men and women - Kneel down for expert help, extract the color characteristics of tomatoes with matlab, and then identify the maturity of tomatoes.
Kneel down for expert help, extract the color characteristics of tomatoes with matlab, and then identify the maturity of tomatoes.
Why do you ask again? Let me tell you something.

Your extraction of color is the same as that of audio. The key is to classify all kinds of color codes, which is easy to do. I'll give you a source program to distinguish audio, which I compiled myself. You can imitate it. Almost. The basic principle is to use BP neural network for identification.

%% Clear environment variables

Chromaticity control center

clear

Extraction and normalization of%% training data prediction data

% download four voice signals

Load data 1 c 1

Load data 2 c2

Load data 3 c3

Load data 4 c4

% 4 characteristic signal matrices are combined into one matrix.

data( 1:500,)=c 1( 1:500,);

data(50 1: 1000,)=c2( 1:500,);

Data (100 1: 1500,) =c3( 1:500,);

Data (150 1:2000,) =c4( 1:500,);

Percentage of random sort from 1 to 2000

K = rand (1, 2000);

[m,n]= sort(k);

% input and output data

Input = data (:,2: 25);

output 1 =data(:, 1);

% Change the output from 1 dimension to 4 dimensions.

For i= 1:2000

Switch output 1(i)

Case 1

output(i,)=[ 1 0 0];

Case 2

output(i,)=[0 1 0 0];

Case 3

output(i,:=[0 0 1 0];

Case 4

output(i,)=[0 0 0 1];

end

end

% randomly selected 1500 samples as training samples and 500 samples as prediction samples.

input _ train = input(n( 1: 1500),:)’;

output _ train = output(n( 1: 1500),:)';

input _ test = input(n( 150 1:2000),:)';

output _ test = output(n( 150 1:2000),:)';

Input data standardization percentage

[inputn,inputps]= mapminmax(input _ train);

%% network structure initialization

innum = 24

midnum = 25

out num = 4;

Weight percentage initialization

w 1=rands(midnum,innum);

b 1=rands(midnum, 1);

w2=rands(midnum,out num);

b2=rands(outnum, 1);

w2 _ 1 = w2; w2 _ 2 = w2 _ 1;

w 1 _ 1 = w 1; w 1 _ 2 = w 1 _ 1;

b 1 _ 1 = b 1; b 1 _ 2 = b 1 _ 1;

B2 _ 1 = B2; B2 _ 2 = B2 _ 1;

Learning rate%

xite=0. 1

Alpha = 0.01;

%% online training

for ii= 1: 10

e(ii)= 0;

Because I =1:1:1500.

%% network prediction output

x=inputn(:,I);

% hidden layer output

For j= 1: 1:midnum

I(j)=inputn(:,i)'*w 1(j,)'+b 1(j);

iout(j)= 1/( 1+exp(-I(j));

end

% output layer output

yn = w2 ' * Iout '+B2;

%% weight threshold correction

% calculation error

e=output_train(:,I)-yn;

E(ii)= E(ii)+sum(ABS(E));

% Calculated weight change rate

dw2 = e * Iout

DB2 = e ';

For j= 1: 1:midnum

s = 1/( 1+exp(-I(j)));

FI(j)= S *( 1-S);

end

For k= 1: 1:innum

For j= 1: 1:midnum

dw 1(k,j)=FI(j)*x(k)*(e( 1)*w2(j, 1)+e(2)*w2(j,2)+e(3)*w2(j,3)+e(4)*w2(j,4));

db 1(j)= FI(j)*(e( 1)* w2(j, 1)+e(2)*w2(j,2)+e(3)*w2(j,3)+e(4)*w2(j,4));

end

end

w 1 = w 1 _ 1+xite * dw 1’+alfa *(w 1 _ 1-w 1 _ 2);

b 1 = b 1 _ 1+xite * db 1 '+alfa *(b 1 _ 1-b 1 _ 2);

w2 = w2 _ 1+xite * dw2 '+alfa *(w2 _ 1-w2 _ 2);

B2 = B2 _ 1+xite * DB2 '+alfa *(B2 _ 1-B2 _ 2);

w 1 _ 2 = w 1 _ 1; w 1 _ 1 = w 1;

w2 _ 2 = w2 _ 1; w2 _ 1 = w2;

b 1 _ 2 = b 1 _ 1; b 1 _ 1 = b 1;

B2 _ 2 = B2 _ 1; B2 _ 1 = B2;

end

end

%% speech feature signal classification

inputn_test=mapminmax('apply ',input_test,input PS);

for ii= 1: 1

For i= 1:500% 1500.

% hidden layer output

For j= 1: 1:midnum

I(j)=inputn_test(:,i)'*w 1(j,)'+b 1(j);

iout(j)= 1/( 1+exp(-I(j));

end

fore(:,I)= w2 ' * Iout '+B2;

end

end

%% result analysis

% according to the network output to find out what kind of data belongs to.

Because i= 1:500

output_fore(i)=find(fore(:,i)==max(fore(:,I));

end

%BP network prediction error

error = output _ fore-output 1(n( 150 1:2000))';

% Draw a classification diagram of the predicted voice category and the actual voice category.

Figure (1)

plot(output_fore,' r ')

continue

plot(output 1(n( 150 1:2000))',' b ')

Legend ("predicted voice category" and "actual voice category")

% drawing error map

Figure (2)

Drawing (error)

Title ('BP network classification error',' fontsize', 12)

Xlabel ('voice signal',' fontsize', 12)

Ylabel ('classification error',' fontsize', 12)

%print -dtiff -r600 1-4

K = zero (1, 4);

% Find out which category the misjudged classification belongs to.

Because i= 1:500

If the error (I) ~ = 0

[b,c]=max(output_test(:,I));

Switch c

Case 1

k( 1)= k( 1)+ 1;

Case 2

k(2)= k(2)+ 1;

Case 3

k(3)= k(3)+ 1;

Case 4

k(4)= k(4)+ 1;

end

end

end

% Find individuals and each category.

Kk = zero (1, 4);

Because i= 1:500

[b,c]=max(output_test(:,I));

Switch c

Case 1

kk( 1)= kk( 1)+ 1;

Case 2

kk(2)= kk(2)+ 1;

Case 3

kk(3)= kk(3)+ 1;

Case 4

kk(4)= kk(4)+ 1;

end

end

Correct rate%

rightridio=(kk-k)。 /kk