13-12-2012-2D-3D Graphic By MatLab

posted on 13 Dec 2010 13:44 by lavalin  in MATLAB
เอกสารประกอบการเรียน >> Dowload
โหลดฉบับแก้ไขใหม่ด้วย
------------------------------------------------------------------------------

แก้ชีทหน้า 6

g   - Green
b   - Blue
c   - Cyan
m  - Magenta
y   - Yellow
k   - Black
w  - White

แก้ชีทหน้า 7,8,9

x = linespace(0,2*pi,20); >> x = linspace(0,2*pi,20);

------------------------------------------------------------------------------
"colormap(bone)" <<เลือกโทนสีในกราฟตามต้องการ

มีโทนให้เลือกคือ
Autumn         - Shades of red and yellow.
Bone             - Gray scale with a tinge of blue.
Colorcube
Cool
copper
Flag
Gray
Jet
Pink
Prism
Spring
Summer
White
Winter
ตัวอย่าง colormap(Cool)
------------------------------------------------------------------------------

[x,y] = meshgrid([-10:0.5:10]); <<หมายความว่า เริ่มตั้งแต่ -10 จนถึง 10 เพิ่มครั้งละ 0.5

aviread - เป็นการอ่านไฟล์วีดีโอเข้ามาทีละเฟรม

------------------------------------------------------------------------------
Test - กลางภาค
basic fn 2 ใหญ่ ข้อละ 4-5 ข้อย่อย ฟังก์ชั่นนี้ทำอะไร หมายถึง?
การสร้าง ฟังก์ชั่น - เขียนฟังก์ชันมีหลังการเขียนอย่างไรบ้าง การสร้างฟังก์ชั่น สร้างฟังก์ชันขึ้นมา
การอธิบายโปรแกรม - โปรแกรที่ให้มาให้ผลอย่างไร รันถึงบรรทัดนี้เกิดอะไรขึ้นบ้าง
คำสั่งเปิดกว้างมา - ถ้าต้องการผลแบบนี้จะแก้ปัญหาอย่างไรใช้วิธีไหนในการแก้ เขียน sudo code มาด้วย
เขียน code ผิดไม่ว่า ดูจากแนวคิด ไอเดีย อธิบายเยอะๆ จะเขียน code เป็นภาษาอะไรก็ได้ทั้งนั้น 
 

29-11-2010

posted on 29 Nov 2010 14:04 by lavalin  in MATLAB

>> help circle

circle.m not found.

Use the Help browser Search tab to search the documentation, or
type "help help" for help command options, such as help for methods.

หมายความว่า circle ไม่มีใน MATLAB

--------------------------------------------------------

การสร้างฟังก์ชั่นใช้งานในMATLAB

 function y = circle(x)
%circle is the function use for circle area computation
%y is circle area
%x is radius
y = pi*(x*x);

Save ในชื่อ circle.m

ที Current Directory ให้เป็นตำแหน่งเดียวกันโฟลเดอร์ที่เซฟ circle.m ไว้

ใน command Window

>> help circle  ก่อนทำการสร้างฟังก์ชั่น

circle.m not found.

Use the Help browser Search tab to search the documentation, or
type "help help" for help command options, such as help for methods.

>> help circle หลังทำการสร้างฟังก์ชั่น
 circle is the function use for circle area computation
 y is circle area
 x is radius

------------------------------------------------------------------

EX

a = imread('ngc6543a.jpg'); //โหลดภาพเข้ามา

a=rgb2gray(a); //เปลี่ยนภาพสีเป็นสีเทา

imshow(a)

x = imhist(a); //สร้างกราฟฮิสโตแกรมจากูปภาพ
figure,plot(x) // โชว์กราฟ
corr2 (x,x) // ฟังก์ชั่นเปรียบเทียบ

ans =

     1

-----------------------------------------------------------------

JOBเปรียบเทียบรูป

//โหลดรูปเข้ามาและเปลี่ยนเป็นโทนสีเทา

x1 = imread('C:\Users\Guest\Desktop\Flower\1.jpg');
x1=rgb2gray(x1);
x2 = imread('C:\Users\Guest\Desktop\Flower\2.jpg');
x2=rgb2gray(x2);
imshow(x2)
x2 = imread('C:\Users\Guest\Desktop\Flower\2.jpg');
x2=rgb2gray(x2);
x3 = imread('C:\Users\Guest\Desktop\Flower\3.jpg');
x3=rgb2gray(x3);
x4 = imread('C:\Users\Guest\Desktop\Flower\4.jpg');
x4=rgb2gray(x4);
x5 = imread('C:\Users\Guest\Desktop\Flower\5.jpg');
x5=rgb2gray(x5);
x6 = imread('C:\Users\Guest\Desktop\Flower\6.jpg');
x7 = imread('C:\Users\Guest\Desktop\Flower\7.jpg');
x8 = imread('C:\Users\Guest\Desktop\Flower\8.jpg');
x9 = imread('C:\Users\Guest\Desktop\Flower\9.jpg');
x6=rgb2gray(x6);
x7=rgb2gray(x7);
x8=rgb2gray(x8);
x9=rgb2gray(x9);

//สร้างกราฟฮิสโตแกรมจากรูปเทาดำ

h1=imhist(x1);
h2=imhist(x2);
h3=imhist(x3);
h4=imhist(x4);
h5=imhist(x5);
h6=imhist(x6);
h7=imhist(x7);
h8=imhist(x8);
h9=imhist(x9);

//สร้างฟังก์ชั่น SAD หาความแตกต่างของรูป โดยเซฟเป็น m-file

function z=SAD(his1,his2)
sum = 0;
for i=1:256
    sum=sum+abs(his1(i)-his2(i));
end
z=sum;
end

//ยังไม่เสร็จ สร้างเมทริกเก็นค่าเปรียบเทียบทั้ง 9 รูป แล้วหาที่น้อยสุดยกเว้น 0 คือรูปที่คล้ายกันที่สุด

ค่าที่มากสุด คือรูปที่ต่างกันมากที่สุด
 

//การบ้านส่งปลายเทอม