资源描述:
《matlab图像处理小结.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.function [center, r] = solve_circle(pt1, pt2, pt3) 2.%Effect: solve the circle which across points 'pt1', 'pt2' and 'pt3' 3.%Inputs: 4.%pt1, pt2, pt3: [x, y] 5.%center: the circle center [x0; y0] 6.%r: the radius of the circle 7.%Author: Su dongcai at 2012/1/2 8.A = zeros(2,
2、2); B = zeros(2, 1); 9.[A(1, :), B(1)] = circle2line(pt1, pt2); 10.[A(2, :), B(2)] = circle2line(pt2, pt3); 11.center = AB; 12.r = norm(pt1' - center); 13. 14.function [A, B] = circle2line(pt1, pt2) 15.%Effect: cast 2 circles equation into 1 linear equation: 16.%(a-x1)^2 + (b
3、-y1)^2 = r^2
4、 17.%
5、==> 2(x1-x2)a + 2(y1-y2)b = (x1^2 + y1^2) - (y2^2 + y2^2) 18.%(a-x2)^2 + (b-y2)^2 = r^2
6、 19.%Inputs: 20.%pt1, pt2: [x1, y1], [x2, y2] 21.%Outputs: 22.%A: 2[x1-x2, y1-y2] 23.%B: (x1^2 + y1^2) - (x2^2 + y2^2) 24.%Author: Su dongcai at 2012/1/2 25.A = 2*(pt
7、1 - pt2); 26.B = norm(pt1)^2 - norm(pt2)^2; closeall;clear;clc;>>i=imread('rice.png');%>>imshow(i);>>background=imopen(i,strel('disk',15));>>i2=imsubtract(i,background);%>>figure,imshow(i2);>>i3=imadjust(i2,stretchlim(i2),[01]);%>>figure,imshow(i3);>>level=graythresh(i3);>>bw=im2bw(i
8、3,level);%>>figure,imshow(bw);>>[labeled,numobjects]=bwlabel(bw,4);graindata=regionprops(labeled,'all');closeall;clear;clc;i=imread('rice.png');background=imopen(i,strel('disk',15));i2=imsubtract(i,background);i3=imadjust(i2,stretchlim(i2),[01]);level=graythresh(i3);bw=im2bw(i3,level)
9、;[labeled,numobjects]=bwlabel(bw,4);data=regionprops(labeled,'all');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2006.6.2closeall;clear;clc;>>i=imread('r.jpg');%>>figure,imshow(i);>>imgray=rgb2gray(i);>>figure,imshow(imgray)>>background=imopen(imgray,strel('disk',15));>>i2
10、=imsubtract(imgray,background);%>>figure,imshow(i2);>>i3=imadjust(i2,stretchlim(i2),[01]);%>>figure,imshow(i3);>>level=graythresh(i3);>>bw=im2bw(i3,level);%>>figure,imshow(bw);>>imnobord=imclearborder(bw,4);%>>figure,imshow(imnobord);>>[labeled,numobjects]=bwlabel(bw,4);>>rgb_label=la
11、bel2r