请仿照下边这段代码写一段代码:(1)直方图均衡化 function Untitled_8_Callback(hObject, eventdata, handles) im=handles.a; sz=length(size(im)); %判断是否为灰度图像 %size:获取数组的行数和列数 %length:数组长度(即行数或列数中的较大值) if sz == 2 equa=histeq(im); %直方图均衡 figure, subplot(121),imhist(im),title('直方图均衡前') subplot(122),imhist(equa),title('直方图均衡后') axes(handles.axes2) imshow(equa,'InitialMagnification','fit'),title('直方图均衡后图') else equa1 = histeq(im(:,:,1)); equa2 = histeq(im(:,:,2)); equa3 = histeq(im(:,:,3)); figure, subplot(231),imhist(im(:,:,1)),title('R分量直方图均衡前'); subplot(232),imhist(im(:,:,2)),title('G分量直方图均衡前'); subplot(233),imhist(im(:,:,3)),title('B分量直方图均衡前'); subplot(234),imhist(equa1),title('R分量直方图均衡前'); subplot(235),imhist(equa2),title('G分量直方图均衡前'); subplot(236),imhist(equa3),title('B分量直方图均衡前'); axes(handles.axes2) imshow(cat(3,equa1,equa2,equa3),'InitialMagnification','fit'),title('直方图均衡后图') end % hObject handle to Untitled_8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 程序源代码以及关键部分注释 (2)canny算法 function Untitled_24_Callback(hObject, eventdata, handles) axes(handles.axes1); d = handles.a; B=getimage(handles.axes1); B = rgb2gray(B); img=edge(B,'canny'); axes(handles.axes2); imshow(img);
时间: 2024-04-29 14:21:55 浏览: 110
histom.rar_uniform histogram_灰度直方图_直方图均衡_直方图均衡化
function my_histeq(hObject, eventdata, handles)
im = handles.a;
sz = length(size(im)); %判断是否为灰度图像
if sz == 2
equa = histeq(im); %直方图均衡
figure,
subplot(121), imhist(im), title('直方图均衡前')
subplot(122), imhist(equa), title('直方图均衡后')
axes(handles.axes2)
imshow(equa, 'InitialMagnification', 'fit'), title('直方图均衡后图')
else
equa1 = histeq(im(:,:,1));
equa2 = histeq(im(:,:,2));
equa3 = histeq(im(:,:,3));
figure,
subplot(231), imhist(im(:,:,1)), title('R分量直方图均衡前');
subplot(232), imhist(im(:,:,2)), title('G分量直方图均衡前');
subplot(233), imhist(im(:,:,3)), title('B分量直方图均衡前');
subplot(234), imhist(equa1), title('R分量直方图均衡前');
subplot(235), imhist(equa2), title('G分量直方图均衡前');
subplot(236), imhist(equa3), title('B分量直方图均衡前');
axes(handles.axes2)
imshow(cat(3,equa1,equa2,equa3), 'InitialMagnification', 'fit'), title('直方图均衡后图')
end
function my_canny(hObject, eventdata, handles)
axes(handles.axes1);
B = getimage(handles.axes1);
B = rgb2gray(B);
img = edge(B, 'canny');
axes(handles.axes2);
imshow(img);
阅读全文