Tải bản đầy đủ - 0 (trang)
Code MATLAB xử lý ảnh và huấn luyện dữ liệu

Code MATLAB xử lý ảnh và huấn luyện dữ liệu

Tải bản đầy đủ - 0trang

global T1;

global T2;

global p;

T1=double(zeros(18,50));

T2=double(zeros(5,50));

i=0;

global cam;

cam = webcam('Logitech');

preview(cam);

set(handles.pushbutton1,'enable','off');

set(handles.pushbutton2,'enable','off');

set(handles.pushbutton3,'enable','off');

set(handles.pushbutton4,'enable','off');

set(handles.pushbutton6,'enable','off');

function popupmenu2_Callback(hObject, eventdata, handles)

global p;

set(handles.pushbutton1,'enable','on');

set(handles.pushbutton2,'enable','on');

set(handles.pushbutton3,'enable','on');

set(handles.pushbutton4,'enable','on');

set(handles.pushbutton6,'enable','on');

p=get(handles.popupmenu2,'value');

function pushbutton1_Callback(hObject, eventdata, handles)

global Q;

global cam;

I = snapshot(cam);

axes(handles.axes1);

imshow(I);

anhxam=rgb2gray(I);

anhnhiphan=im2bw(anhxam,graythresh(anhxam));

loc=edge(anhnhiphan,'canny',graythresh(anhxam));

xuly1=bwareaopen(loc,20);

se = strel('disk',1);

xuly2=imclose(xuly1,se);

r=I(:,:,1);

r=double(r);

[x1,z1]=size(r);

R = sum(r,1);

Sr = sum(R,2);

TBr = Sr/(x1*z1);

maxR = max( max(r));

minR = min(min(r));

stdR = std(std(r));

g=I(:,:,2);

g=double(g);

[x2,z2]=size(g);

G = sum(g,1);

Sg = sum(G,2);

TBg = Sg/(x2*z2);

maxG = max( max(g));

minG = min(min(g));

stdG = std(std(g));

b=I(:,:,3);

b=double(b);

[x3,z3]=size(b);

B = sum(b,1);

Sb = sum(B,2);

TBb = Sb/(x3*z3);



maxB = max( max(b));

minB = min(min(b));

stdB = std(std(b));

for mm = 1:size(xuly2,1)

for nn = 1:size(xuly2,2)

if ((xuly2(mm,nn) == 1))

D(mm,nn,:) = [0 255 0]; % green outline in shapes

end

end

end

axes(handles.axes2);

imshow(D);

[laythongso num] = bwlabel(xuly2,8);

thongso = regionprops(laythongso,'all');

dtich =double( uint16(zeros(1,num)));

chuvi = double(uint16(zeros(1,num)));

dai = double(uint16(zeros(1,num)));

rong =double(uint16(zeros(1,num)));

tyledairong = double(uint16(zeros(1,num)));

dotron=double(uint8(zeros(1,num)));

for i = 1 : num

dtich(i) = thongso(i).FilledArea;

chuvi(i) = thongso(i).Perimeter;

dai(i) = thongso(i).MajorAxisLength;

rong(i) = thongso(i).MinorAxisLength;

dotron(i) = (4*dtich(i)*pi)/(chuvi(i).^2);

tyledairong(i) = dai(i)/rong(i);



end

dtichTB = sum(dtich,2)/num;

chuviTB= sum(chuvi,2)/num;

daiTB= sum(dai,2)/num;

rongTB = sum(rong,2)/num;

dotronTB = sum(dotron,2)/num;

tyledairongTB = sum(tyledairong,2)/num;

set(handles.edit1,'String',{strcat('Dien tich TB



=',num2str( dtichTB)),strcat( 'Chu vi TB =', num2str(chuviTB)),...

strcat('Chieu dai TB =', num2str(daiTB)),strcat('Chieu rong TB = ',

num2str(rongTB)),...

strcat('Do tron TB =' , num2str(dotronTB)),strcat('Ty le dai rong TB

=', num2str(tyledairongTB)),...

strcat('Max R =', num2str(maxR)),strcat('Max G =',

num2str(maxG)),strcat('Max B =', num2str(maxB)),...

strcat('Min R =', num2str(minR)),strcat('Min G =',

num2str(minG)),strcat('Min B =', num2str(minB)),...

strcat('Std R =', num2str(stdR)),strcat('Std G =',

num2str(stdG)),strcat('Std B =', num2str(stdB)),...

strcat('Trung binh R =', num2str(TBr)),strcat('Trung binh G =',

num2str(TBg)),strcat('Trung binh B =', num2str(TBb))});

Q =

[dtichTB;chuviTB;daiTB;rongTB;dotronTB;tyledairongTB;maxR;maxG;maxB;minR;mi

nG;minB;stdR;stdG;stdB;TBr;TBg;TBb]



function pushbutton2_Callback(hObject,

global T1;

global T2;

save('T1');

save('T2');

xlswrite('x',T1);

xlswrite('y',T2);

nntool;

function pushbutton3_Callback(hObject,

global i;

global Q;

global T1;

global T2;

global p;

i=i+1;

Q=double(Q);

p = get(handles.popupmenu2,'value');

switch p

case 1

A=[1;0;0;0;0];

case 2

A=[0;1;0;0;0];

case 3

A=[0;0;1;0;0];

case 4

A=[0;0;0;1;0];

case 5

A=[0;0;0;0;1];

end

T1(:,i) = Q

T2(:,i) = A

function pushbutton4_Callback(hObject,

closepreview

close all

clear all

function pushbutton6_Callback(hObject,

closepreview;

clear all;

close trainnn;

doannhandang;



eventdata, handles)



eventdata, handles)



eventdata, handles)



eventdata, handles)



 Code MATLAB nhận dạng giống lúa.

function doannhandang_OpeningFcn(hObject, eventdata, handles, varargin)

global Q;

global cam1;

cam1=webcam('Logitech');

cam1.Resolution='640x480';

preview(cam1);

global s;

delete(instrfind({'Port'},{'all'}));

s = serial('COM3');

s.BytesAvailableFcnMode = 'byte';

s.BytesAvailableFcnCount = 5;

s.BytesAvailableFcn = {@BytesAvailable_callback,handles};

fopen(s);

function pushbutton1_Callback(hObject, eventdata, handles)

global Q;

load netlua network1 T1 T2;

t = sim(network1,Q);

t= compet(t);

set(handles.edit19,'String',num2str(nhandang(t)));



function pushbutton2_Callback(hObject, eventdata, handles)

global cam1;

global Q;

I=snapshot(cam1);

axes(handles.axes1);

imshow(I);

anhxam=rgb2gray(I);

anhnhiphan=im2bw(anhxam,graythresh(anhxam));

loc=edge(anhnhiphan,'canny',graythresh(anhxam));

xuly1=bwareaopen(loc,20);

se = strel('disk',1);

xuly2 = imclose(xuly1,se);

r=I(:,:,1);

r=double(r);

[x1,z1]=size(r);

R = sum(r,1);

Sr = sum(R,2);

TBr = Sr/(x1*z1);

maxR = max( max(r));

minR = min(min(r));

stdR = std(std(r));

g=I(:,:,2);

g=double(g);

[x2,z2]=size(g);

G = sum(g,1);

Sg = sum(G,2);

TBg = Sg/(x2*z2);

maxG = max( max(g));

minG = min(min(g));

stdG = std(std(g));

b=I(:,:,3);

b=double(b);

[x3,z3]=size(b);

B = sum(b,1);

Sb = sum(B,2);

TBb = Sb/(x3*z3);

maxB = max( max(b));

minB = min(min(b));

stdB = std(std(b));

for mm = 1:size(xuly2,1)

for nn = 1:size(xuly2,2)

if ((xuly2(mm,nn) == 1))

X(mm,nn,:) = [0 255 0]; % green outline in shape

end

end

end

axes(handles.axes2);

imshow(X);

[laythongso num] = bwlabel(xuly2,8);

thongso = regionprops(laythongso,'all');

dtich =double( uint16(zeros(1,num)));

chuvi = double(uint16(zeros(1,num)));

dai = double(uint16(zeros(1,num)));

rong =double(uint16(zeros(1,num)));

tyledairong = double(uint16(zeros(1,num)));

dotron=double(uint8(zeros(1,num)));

for i = 1 : num

dtich(i) = thongso(i).FilledArea;

chuvi(i) = thongso(i).Perimeter;

dai(i) = thongso(i).MajorAxisLength;



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Code MATLAB xử lý ảnh và huấn luyện dữ liệu

Tải bản đầy đủ ngay(0 tr)

×