1.写一段代码画出一个图像的灰度直方图(不能用MATLAB自带的
%% 灰度均衡化5261函4102数 自编i = rgb2gray(imread('lena.png'));matlab_i=histeq(i);for j=1:1:256num_j(j)=max(size(find(j-1==i)));endfor op=1:1:size(i,1)for pk=1:1:size(i,2)gray=i(op,pk,1);gray1=sum(num_j(1:gray+1))/(size(i,1)*size(i,2))*255;custom_i(op,pk,1)=uint8(round(gray1));endendfigure;subplot(231),imshow(i);title('原图1653灰度化回');subplot(234),imhist(i);subplot(232),imshow(matlab_i);title('matlab灰度均衡答');subplot(235),imhist(matlab_i);subplot(233),imshow(custom_i);title('自定义灰度均衡');subplot(236),imhist(custom_i);。
2.strcmp函数怎么写
要从内存的角度去看这个问题
首先,int
strcmp(char
*s,char
*t)这个函数的参数是2个指针分别指向内存的2个不同位置
for(
;
*s
==
*t;s++,t++)
是使得2个指针比较,相同就向后移动
if(*s
==
0)
return
0
指针为空,返回false.
不为空返回2指针内存的地址差
3.C语言自己写strcpy函数怎么写
楼主听我细细说,这个简单,我给你写的这个比普通的strcpy还多了一个功能呢,那就是多了的话,自动截取那么源字符串那么长的子串放入源字符串。
char * strcpy(char *to, char *from)
{
char *tmpTo = to, *tmpFrom = from;
if(from == NULL || to == from)
{
return to;
}
int counter = 0;
while(counter {
*tmpTo++ = *tmpFrom++;
counter++;
}
*tmpTo = '\0';
return to;
}
转载请注明出处育才学习网 » imhist函数怎么写