0.命令:

doc 查看函数的帮助文档,eg:>>doc imread; global 关键字:Declare global variables global X; 在主函数中声明,然后再对变量赋值,那么在其他.m中,先做同样的方法进行声明,就可以在该.m中使用该值

常用函数

abs Absolute value and complex magnitude atan Inverse tangent; result in radians; eg.atan(1)/(2pi)360=45 axis Axis scaling and appearance axis([xmin xmax ymin ymax])

bwareaopen

BW2 = bwareaopen(BW,P,conn) %删除二值图像BW中面积小于P的对象,默认情况下conn使用8邻域 得先使用im2bw对图像做二值化处理,(im2bw的第二个参数是浮点数); bwdist Distance transform of binary image;D = bwdist(BW) D表示零元素所在的位置靠近非零元素位置的最短距离;

bwlabel

L = bwlabel(BW,n) 返回一个和BW大小相同的L矩阵,包含了标记了BW中每个连通区域的类别标签,这些标签的值为1、2、num(连通区域的个数)。n的值为4或8,表示是按4连通寻找区域,还是8连通寻找,默认为8。 4连通或8连通是图像处理里的基本感念:而8连通,是说一个像素,如果和其他像素在上、下、左、右、左上角、左下角、右上角或右下角连接着,则认为他们是联通的;4连通是指,如果像素的位置在其他像素相邻的上、下、左或右,则认为他们是连接着的,连通的,在左上角、左下角、右上角或右下角连接,则不认为他们连通。请注意“或”字的含义,就是满足其中一个条件就认为是连通的。 [L,num] = bwlabel(BW,n)这里num返回的就是BW中连通区域的个数。 csvread csvread:读取csv文件,如:M = csvread('Single_Red_016.csv'); csvwrite csvwrite(strcat('Single_Red_',num2str(Level(loop)),'.csv'),DemuraData); contour contour(Z,n) draws a contour plot of matrix Z with n contour levels. diff Y = diff(X) calculates differences between adjacent elements of X dir dir lists the files and folders in the MATLAB current folder

FolderList=dir(strcat(FolderPath,'*.BMP'));%Get all the .bmp file and store them at FileList  
FileNum=length(FolderList);  
ImageName=FolderList(imageCount).name;   
disp 在命令行中显示语句 disp(['localiztion radius is: ' num2str(rad) ' pixels']); double Convert to double precision edge Find edges in grayscale image BW4=edge(I,'log'); eps Floating-point relative accuracy;默认最小浮点数精度(2.2204e-016) *exist Check existence of variable, function, folder, or class

if(~exist('mu','var')) 
mu=0.2; 
end
false false(m, n) or false([m, n]) is an m-by-n matrix of logical zeros. figure figure:创建一个新的图形界面; find Find indices and values of nonzero elements ind = find(X) locates all nonzero elements of array X, and returns the linear indices of those elements in vector ind. If X is a row vector, then ind is a row vector; otherwise, ind is a column vector. If X contains no nonzero elements or is an empty array, then ind is an empty array. Example 1 X = [1 0 4 -3 0 0 0 8 6]; indices = find(X) returns linear indices for the nonzero entries of X. indices = 1 3 4 8 9 fliplr Flip matrix left to right If A is the 3-by-2 matrix,
A =
1    4
2    5
3    6
then fliplr(A) produces
4    1
5    2
6    3
If A is a row vector,
A =
1    3    5    7    9
then fliplr(A) produces
9    7    5    3    1
flipud Flip matrix up to down If A is the 3-by-2 matrix, A = 1 4 2 5 3 6 then flipud(A) produces
3    6
2    5
1    4
floor B = floor(A) rounds the elements of A to the nearest integers less than or equal to A fopen Open file, or obtain information about open files
%输入文本到txt中
fid = fopen('E:\Original\FileList.txt', 'wt');
fprintf(fid,'%s\n',ImageName);
fclose(fid);
fprintf 将数据保存到指定为文件中
%将二维数据以整型形式保存到建立的example8bit.txt文件中
fid=fopen('E:\sunwork\WorkProject\demura\Programe\example8bit.txt','wt');
for i=1:480
for j=1:68
if j==68
fprintf(fid,'%d',outdata(i,j));
else
fprintf(fid,'%d,',outdata(i,j));
end
end
fprintf(fid,'\n');
end
fclose(fid);
fspecial Create predefined 2-D filter h = fspecial(type, parameters) accepts the filter specified by type plus additional modifying parameters particular to the type of filter chosen. If you omit these arguments, fspecial uses default values for the parameters
sigma = 3;
gaussian_filter = fspecial('gaussian',[15  15], sigma);
C16 = imfilter(C16_ori,gaussian_filter,'conv','replicate','same');
grid on 使用plot绘制图像时,加上该句,会在XOY轴上绘制网格 hex2dec Convert hexadecimal number string to decimal number hex2dec('3ff') ans = 1023 hist 显示数据的直方图分布 data=[4 1 2 3 1 3 1 3 2 4]; z=hist(data,4) 将data分为4组,则每一组间隔为0.75=(4-1)/4=(max-min)/num;[1-1.75],[1.75-2.5],[2.5-3.25],[3.25-4]4组,落在各组上的Data个数分别为z =3 2 3 2; im2bw 图像二值化处理 Convert image to binary image, based on threshold
tt=graythresh(I);
I=im2bw(I,tt);
figure;imshow(I);
im2double Convert image to double precision; imcrop 图像的裁剪 imfilte B = imfilter(A, H) filters the multidimensional array A with the multidimensional filter H. The array A can be logical or a nonsparse numeric array of any class and dimension. The result B has the same size and class as A imhist imhist:显示图像的直方图:如: figure; imhist(image_in(:,:,2));axis([0 255 1 25000]); imshow imshow:显示一副图像,该图像一定是uint8类型的 imresize Resize image J = imresize(I, 0.5); I_new=imresize(I,[2960,1440]); imrotate 使用imrotate函数进行图像的旋转。 imrotate(imagenamereaded,270,'nearest'); imwrite 保存图像,保存的默认路径为当前workspace路径 imwrite(image,strcat('Green',num2str(32),'.bmp')); ind2sub 把矩阵中元素单下标标识转换为该元素在矩阵中对应的全下标标识。 是把矩阵A中单下标标识8的元素转换为对应的的第二行第三列全下标标识(2,3)。 A = [1 12 13; 24 35 26;47,28,19];[I,J]=ind2sub(size(A),8) I =2 J =3 legend 对绘制的曲线做描述
%绘制曲线,并对曲线做描述
% plot(x,y,'r',x,yGoal,'g');
% hleg1=legend('plot curve','Gamma Curve');%分别解释了曲线'y'与曲线'yGoal'
% set(hleg1,'Location','NorthWest')
% title('Luminance plot');
% axis([0 250 0 300]);
% grid on;
length Length of vector or largest array dimension mat2gray Convert matrix to grayscale image max 求数组最大值,若求矩阵最大值,需要使用max(max(Image)); mean mean:求数组均值,若求矩阵均值,需要使用mean(mean(Image)); medfilt2 2-D median filtering B = medfilt2(A, [m n]) performs median filtering of the matrix A in two dimensions. Each output pixel contains the median value in the m-by-n neighborhood around the corresponding pixel in the input image. medfilt2 pads the image with 0s on the edges, so the median values for the points within [m n]/2 of the edges might appear distorted. median Median value of array M = median(A) returns the median values of the elements along different dimensions of an array. A should be of type single or double. median取中值函数,若输入参数值矩阵M,先把矩阵变成向量然后再使用此函数;不能直接使用两次median(median(M)),第一次会计算每一列的中值,然后再把第一次结果,再做一次中值计算,这样的结果不正确。 median(A(:)),把矩阵A变成向量,这样才正确; meshgrid Generate X and Y arrays for 3-D plots; [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y. [X,Y] = meshgrid(1:3,10:14) X =
 1     2     3
1     2     3
1     2     3
1     2     3
1     2     3
Y =
10    10    10
11    11    11
12    12    12
13    13    13
14    14    14
min min:求数组最小值,若求矩阵最小值,需要使用min(min(Image)); mod Modulus after division M = mod(X,Y) if Y ~= 0, returns X - n.*Y where n = floor(X./Y). 取余运算:eg. mod(17,5)=2 num2str Convert number to string numel Number of elements in array or subscripted array expression padarray B = padarray(A, padsize) B = padarray(A, padsize, padval) B = padarray(A, padsize, padval, direction) Description B = padarray(A, padsize) pads array A with 0's (zeros). padsize is a vector of nonnegative integers that specifies both the amount of padding to add and the dimension along which to add it. The value of an element in the vector specifies the amount of padding to add. The order of the element in the vector specifies the dimension along which to add the padding. For example, a padsize value of [2 3] means add 2 elements of padding along the first dimension and 3 elements of padding along the second dimension. By default, paddarray adds padding before the first element and after the last element along the specified dimension. B = padarray(A, padsize, padval) pads array A where padval specifies the value to use as the pad value. padarray uses the value 0 (zero) as the default. padval can be a scalar that specifies the pad value directly or one of the following text strings that specifies the method padarray uses to determine the values of the elements added as padding. K>> I=[1,2;1,2];padarray(I,[1,1],1,'pre') ans =
 1     1     1
1     1     2
1     1     2
K>> I=[1,2;1,2];padarray(I,[2,1],1,'pre') ans =
 1     1     1
1     1     1
1     1     2
1     1     2
polyfit 多项式曲线拟合
%多项式曲线拟合
Level=[16,32,64,128,192,240];
LevelRLuminance=[0.152421758,1.261118531,8.612735748,41.23416519,111.7099838,191.9445038];
y1=polyfit(Level,LevelRLuminance,4);%返回多项式系数
z=polyval(y1,Level);%Level对应的曲线的值
plot(Level,LevelRLuminance,'r*',Level,z,'b')
rand Uniformly distributed pseudorandom numbers Generate values from the uniform distribution on the interval [a, b]. eg. r = a + (b-a).*rand(100,1); randsrc Generate random matrix using prescribed alphabet
%生成10个指定概率的数据
alphabet = [1 4 6]; prob = [0.1 0.4 0.5];
randsrc(10,1,[alphabet; prob])
randn Normally distributed pseudorandom numbers Generate values from a normal distribution with mean 1 and standard deviation 2. r = 1 + 2.*randn(100,1); regionprops Measure properties of image regions 测量图像区域的属性
%统计区域面积
BW =[1 1 1 0 0 0 1 1
1 1 1 0 1 1 0 0
1 1 1 0 1 1 0 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 0 0 0 0];
[L num]=bwlabel(BW,4);%使用4联通分割确定二值图像的区域(num区域分割的个数)
STATS = regionprops(L, 'Area');%返回每一个区域的面积(像素点个数)
Position= regionprops(L,'Centroid'); %返回每一个区域的质心坐标(Position(1)表示第一个区域的质心位置)
List= regionprops(L,'PixelList');%统计区域每一个像素点的坐标
reshape Reshape array B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken column-wise from A. An error results if A does not have m*n elements.
Reshape a 3-by-4 matrix into a 2-by-6 matrix.  
A =
1    4    7    10
2    5    8    11
3    6    9    12        
B = reshape(A,2,6)        
B =
1    3    5    7    9   11
2    4    6    8   10   12  
rot90 Rotate matrix 90 degrees round Y = round(X) rounds the elements of X to the nearest integers. size Array dimensions eg.[height,width,dimention]=size(Pic); size:求数组或者矩阵的大小,如求图像矩阵的大小: smooth yy = smooth(y) smooths the data in the column vector y using a moving average filter. Results are returned in the column vector yy. The default span for the moving average is 5. The first few elements of yy are given by yy(1) = y(1) yy(2) = (y(1) + y(2) + y(3))/3 yy(3) = (y(1) + y(2) + y(3) + y(4) + y(5))/5 yy(4) = (y(2) + y(3) + y(4) + y(5) + y(6))/5 std2 std2:计算矩阵的标准方差:std2Value=std2(image_in(:,:,2)) strcat 链接字符的函数 strcat(filename1,'*Green'); strrep Find and replace substring modifiedStr = strrep(origStr, oldSubstr, newSubstr) eg.strrep(ImageName,'.BMP','Left') sub2ind 把矩阵中元素全下标标识转换为该元素在矩阵中对应的单下标标识。 A = [1 12 13; 24 35 26;47,28,19]; f=sub2ind(size(A), 2, 3)%即把矩阵A中第二行第三列的元素的全下标标识(2,3)转换为对应的单下标标识8,即该元素从第一列顺次数过去是第八号元素。f = 8 subplot subplot:在同一图形窗口界面显示多个图像: surf
%绘制3D图像
[height,width]=size(MRadiant);
MRadiant = flip(MRdiant,1);%对数据做一次镜像,这样才会与其对应的电脑显示的图像方向一致;
surf(1:width,1:height,MRadiant);
axis([1 720 1 1280 0 15])
title('Radiant Green64')
shading interp;  
text Create text object in current axes ; text(x,y,'string') adds the string in quotes to the location specified by the point (x,y) x and y must be numbers of class double. text(100,100,'FontSize',10) ; text(100,100,'Color','white') ; textscan Read formatted data from text file or string C = textscan(fid, 'format') reads data from an open text file identified by the file identifier fid into cell array C.
%读取txt文件,文件数据会存在放cell中;
fid = fopen('TenBitData.txt','r');
TenBitData = textscan(fid,'%s');
TenBitData{1,1}(1);%使用txt文件的第一个元素
hex2dec(TenBitData{1,1}(1));%将读取16进制字符转换成十进制
length(TenBitData{1,1});%文件元素的长度。
fclose(fid);
tic tic, toc.Measure performance using stopwatch timer eg.tStart=tic;any_statements;tElapsed=toc(tStart) title title:对显示的界面添加标题eg: title(strcat(filename1{cc},'Blue'));
height = size(image_in,1); width = size(image_in,2);
%批量处理图片
>[ filename, pathname ] = uigetfile( {  '*.*' },'Your File','E:\sunwork\analyzeMuraData\' ,'MultiSelect', 'on');
if ~iscell(filename)
filename1{1}=filename;
else
filename1=filename;
end

image_num=length(filename1);
for cc = 1:image_num %process the picture
image_in = imread([pathname   filename1{cc}]);
height = size(image_in,1);
width = size(image_in,2);
....
end
uigetfile Open standard dialog box for retrieving files
%通过界面操作读取路径下的任意文件
% [ filename, pathname ] = uigetfile( {  '*.*' },'Your File','E:\sunwork\WorkProject\demura\Programe\demura\' ,'MultiSelect', 'on');
% if ~iscell(filename)
%     filename1{1}=filename;
% else
%     filename1=filename;
% end
% imageAccumulate=zeros(1280,720);
% image_num=length(filename1);
% for cc = 1:image_num %process the picture
%      image_in = imread([pathname   filename1{cc}]);
%      image_in=double(rgb2gray(image_in));
%      height = size(image_in,1);
%      width = size(image_in,2);
% end
vpa Variable precision arithmetic-help控制运算精度 vpa(sqrt(2),3)=1.41; a=vpa(sqrt(2),5)=1.4142; uint8 uint8:将数据转换成uint8类型,eg:ProducePic=uint8(ProducePic); waitbar 程序运行进度条显示
%进度条的使用
waitbarHeader = waitbar(0,'Please wait...');%创建句柄
for i=1:128000
i=i+1;
str=['正在运行中..',num2str(i),'/128000'];%进度条文本
waitbar(i/1280,waitbarHeader,str);%显示进度条
end
close(waitbarHeader);%关闭句柄
whos who, whos List variables in workspace

wavedec2

1、实现图像(即二维信号)的多层分解,多层,即多尺度. 2、对图像X用wname小波基函数实现N层分解 3、c为各层分解系数,s为各层分解系数长度,也就是大小. 4、首先訊號進來,進行高低頻過濾,主要是通過卷積的方式,然後在進行降采樣,大概就是將上一步所生成樣本進行篩選。通過降采樣就可以得到近似係數(approximation coefficient)和細節係數(detail coefficient)。
[C,S] = wavedec2(X,N,'wname')
When X represents an indexed image, X, as well as the output arrays cA,cH,cV, and cD are m-by-n matrices. When X represents a truecolor image, it is an m-by-n-by-3 array, where each m-by-n matrix represents a red, green, or blue color plane concatenated along the third dimension. The size of vector C and the size of matrix S depend on the type of analyzed image. For a truecolor image, the decomposition vector C and the corresponding bookkeeping matrix S can be represented as follows. 1、A(N)代表第N层低频系数,H(N)|V(N)|D(N)代表第N层高频系数,分别是水平,垂直,对角高频; 2、s的结构:是储存各层分解系数长度的, 第一行:A(N)的长度(其实是A(N)的原矩阵的行数和列数), 第二行:是H(N)|V(N)|D(N)|的长度, 第三行:是H(N-1)|V(N-1)|D(N-1)的长度, 倒数第二行:是H(1)|V(1)|D(1)长度, 最后一行是X的长度(大小) 3、举例X=(128,128),设置N=2; s=[37,37;37,37;67,67;128,128] 则C向量的组成是[3737个A(2)系数,3737个H(2)|V(2)|D(2)系数,6767个H(1)|V(1)|D(1)系数,]共18943个元素(3737+37373+67673=18943) 每个向量是一个矩阵的每列转置的组合存储。原文:Each vector is thevector column-wise storage of a matrix. 这是你理解A(N) H(N) | V(N) |D(N) 的关键。 图中D表示H,V,D方向的系数; xlsread xlsread:读取xlsx文件:MRadiant= xlsread('NoMura.xlsx', 15, 'B2:AAS1281');%第15张sheet的数据 xlswrite xlswrite:保存数据到EXCEL中 xlswrite('E:\sunwork\WorkProject\demura\Programe\PSNR\test.xlsx', Data, 'sheet1'); %将数据Data保存在指定路径下的text.xlsx的sheet1中 zeros zeros:初始化数组,矩阵,图像为0,如:array=zeros(3,1);Matirx=zeros(3,3);Image=uint8(zeros(512,512,3); ##3.基本操作 clc; clear all; close all; strcat:连接字符,eg:strcat(filename1{cc},'***Green'); #小程序 ##1.归一化数据矩阵为图像 背景: 对于很多时候,面对大量的数据,我们希望能够直观的感觉到数据的变化,即对数据做出定性的分析,这时,我们可以将数据(这里针对的二维数据矩阵)归一化成图像,来主观分析。 举例:将一个与显示屏亮度有关的csv二维数据矩阵,以图像R分量的形式展现。 原理: 数据标准化(归一化)处理是数据挖掘的一项基础工作,不同评价指标往往具有不同的量纲和量纲单位,这样的情况会影响到数据分析的结果,为了消除指标之间的量纲影响,需要进行数据标准化处理,以解决数据指标之间的可比性。原始数据经过数据标准化处理后,各指标处于同一数量级,适合进行综合对比评价。以下是两种常用的归一化方法: 一、min-max标准化(Min-Max Normalization) 也称为离差标准化,是对原始数据的线性变换,使结果值映射到[0 - 1]之间。转换函数如下: $$x^*=\frac{x-min}{(max-min)}$$ 其中max为样本数据的最大值,min为样本数据的最小值。这种方法有个缺陷就是当有新数据加入时,可能导致max和min的变化,需要重新定义。 对于本例,需要将上述结果归一化到[0,1]的数据乘以255。 二、Z-score标准化方法 这种方法给予原始数据的均值(mean)和标准差(standard deviation)进行数据的标准化。经过处理的数据符合标准正态分布,即均值为0,标准差为1,转化函数为: 其中为所有样本数据的均值,为所有样本数据的标准差。 程序:
clc; clear all; close all; %imread csv file,than normalization the csv to an image Y=zeros(1280,720); image0=zeros(1280,720,3); image0=uint8(image0); M = csvread('Single_Red_016.csv'); maxValue=max(max(M)); minValue=min(min(M)); for i=1:1280 for j=1:720 Y(i,j)=(M(i,j)-minValue)/(maxValue-minValue)*255; end end image0(:,:,1)=Y; imshow(image0);
##2.批量读取图片
%批量处理图片
>[ filename, pathname ] = uigetfile( {  '*.*' },'Your File','E:\sunwork\analyzeMuraData\' ,'MultiSelect', 'on');
if ~iscell(filename)
filename1{1}=filename;
else
filename1=filename;
end

image_num=length(filename1);
for cc = 1:image_num %process the picture
image_in = imread([pathname   filename1{cc}]);
height = size(image_in,1);
width = size(image_in,2);
....
end
##3.进度条使用
%进度条的使用
waitbarHeader = waitbar(0,'Please wait...');%创建句柄
for i=1:1280
for j=1:720
M(i,j)=power(M(i,j),1/2.2);
Y(i,j)=(M(i,j)-minValue)/(maxValue-minValue)*255;
end

str=['正在运行中..',num2str(i),'/1280'];%进度条文本
waitbar(i/1280,waitbarHeader,str);%显示进度条
end
close(waitbarHeader);%关闭句柄
##4.曲线拟合 已知横坐标6个点Level,和其对应的钟作彪6个点,LevelRLuminance,即(Level,LevelRLuminance), 求中间5条线段的直线方程系数k与b(y=kx+b)
%进度条的使用
clc;
clear all;
close all;

Level=[16,32,64,128,192,240];
LevelRLuminance=[0.152421758,1.261118531,8.612735748,41.23416519,111.7099838,191.9445038];

%y=k*x+b,five line function
% k=zeros(1,5);
% b=zeros(1,5);
% 
% for i=1:5
%     k(i)=(LevelRLuminance(i+1)-LevelRLuminance(i))/(Level(i+1)-Level(i));
%     b(i)=LevelRLuminance(i)-(LevelRLuminance(i+1)-LevelRLuminance(i))/(Level(i+1)-Level(i))*Level(i);
% end

% y=a*power(x,2)+c
a=zeros(1,5);%gamma
c=zeros(1,5);%Luminance

for i=1:5
a(i)=(LevelRLuminance(i+1)-LevelRLuminance(i))/(power(Level(i+1),2)-power(Level(i),2));
c(i)=LevelRLuminance(i)-a(i)*power(Level(i),2);

end


%y=a*power(x,2)+c  curve
x=16:240;
y=(a(1)*power(x,2)+c(1)).*(x>=16&x<32)
+(a(2)*power(x,2)+c(2)).*(x>=32&x<64)
+(a(3)*power(x,2)+c(3)).*(x>=64&x<128)
+(a(4)*power(x,2)+c(4)).*(x>=128&x<192)
+(a(5)*power(x,2)+c(5)).*(x>=192&x<=240);%actual curve
yGoal=350*(power(x/255,2.2));%goal curve

plot(x,y,'r',x,yGoal,'g');
axis([0 250 0 300]);
grid on;
##5.消除图像的杂点 背景:一个黑白二值图像中,存在着很多的杂乱的点,且块状的白色斑点之间因单个像素点而存在着区域,本方法可以消除杂乱的噪声点,且切断块状斑点之间较细的连接线(称为断桥方法);图像用刀切成尽量成矩形的小块。 Figure 1. 图示 拆桥原理示意图(STEP=3) Figure 2. 小区域炸点消除 Figure 3. 大区域连接点的断裂 分析:经过一次丢“窄桥”动作之后,原图中小的区域会变得更加小(如上图),然后我们可以通过丢“小区域”的后续动作将这些小区域丢掉;对于那些的大的区域存在的这种桥会被拆掉,这样检测出的Mura区域会因拆桥动作而被分割成更小的单元,也减少了外接矩形存在部分重合的可能性。 STEP值选择的越大,就会有更大的点被腐蚀掉,原图像被削的越小且越矩形化 步骤: 1) 确定白斑点为基础点(i,j),默认已经有一个白斑点k=1; 2) 水平方向拆桥:搜索(遇到边缘需停止)左边的STEP-1个点,若为白斑点则计数k++,若不是则停止左边的搜索,向右边搜索,若搜索到白斑点则计数k++,否则停止搜索,统计水平方向的连续白斑点的个数k,若k小于STEP则认为这些白斑点为“桥”,将其拆除,即image(i,j,:)=0; 3) 垂直方向拆桥:原理同上,此时需重新初始化k=1; 4) 可以选择多次断桥循环,再次断桥之后小区域会消失。图像会被再次分割。
%matlab code 断桥
clc;
clear all;
close all;

SegImage=imread('Seg.bmp');
[height,width,dimention]=size(SegImage);
figure;imshow(SegImage);title('SegImageOriginal');

%=================Break bridge=======================================
%=================sunlinju 2017/1/12=================================
STEP=20;
BREAKTIMES=1;
for times=1:BREAKTIMES
for i=1:height
for j=1:width

if  SegImage(i,j,1)==255
k=1;
for m=1:STEP-1 %break Horiztal bridge
if j-m>0
if  SegImage(i,j-m,1)==255
k=k+1;
else
break;
end
end
end
for m=1:STEP-1
if j+m<=width
if  SegImage(i,j+m,1)==255
k=k+1;
else
break;
end
end
end

if k<STEP
SegImage(i,j,:)=0;
end

k=1;
for m=1:STEP-1  %break vertical bridge
if i-m>0
if  SegImage(i-m,j,1)==255
k=k+1;
else
break;
end
end
end
for m=1:STEP-1
if i+m<=height
if  SegImage(i+m,j,1)==255
k=k+1;
else
break;
end
end
end

if k<STEP
SegImage(i,j,:)=0;
end
end
end
end
end

figure;imshow(SegImage);title(strcat('SegImageBreakBridge','STEP=',num2str(STEP)));  

##9.注意事项 1、在使用imshow显示一副图像时,如果图像变量I是通过赋值得到的,那么该图像变量在定义时一定要是定义或者转换为uint8类型的。
image0=zeros(1280,720,3); image0=uint8(image0);%必须转换 ....... image0(:,:,1)=Y; imshow(image0);