matlab建立dat文件简介

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

% Step 1: Read image Read in

RGB = imread('pic4.jpg');

RGB=imresize(RGB,[1029,1029]);

% Step 2: Convert image from rgb to gray

GRAY = rgb2gray(RGB);

% Step 3A:After eliminating the noise

s=fftshift(fft2(GRAY));

[a,b]=size(GRAY);

n=3;%Here take the order n comparison,n=1,2,3...

d0=30; %Here d0 is the cutoff frequency,d0=10,20,30,...

n1=fix(a/2);

n2=fix(b/2);

for i=1:a

for j=1:b

d=sqrt((i-n1)^2+(j-n2)^2);

h=1/(1+0.414*(d/d0)^(2*n));

s(i,j)=h*s(i,j);

end

end

s=uint8(real(ifft2(ifftshift(s))));

subplot(121),imshow(GRAY);

title('Grayscale');

subplot(122),imshow(s);

title('Image eliminated noise');

% Step 3B: Threshold the image Convert the image to black and white in order % to prepare for boundary tracing using bwboundaries.

figure,imhist(s);

title('Histogram');

[CStad,xs]=imhist(s);

hold on;

plot(xs,CStad,'r');

% save('Cstad.dat', 'CStad');

% close all;

%Step3C: Two values, determined in accordance with 70/255 threshold,

%dividing the target and background

Inew=im2bw(s,70/255);

figure;imshow(Inew);

title('Image after thresholding');

fid = fopen('CStad.dat','wt');

fprintf(fid,'%g\n', CStad); %\n 换行

fclose(fid);

相关文档
最新文档