matlab 联合modelsim 调试图片

来源:互联网 发布:php能开发什么 编辑:程序博客网 时间:2024/06/05 21:04


modelsim 中调试图片很不方便,比如边沿检测,中值滤波等,需要把图像数据输入,然后输出,非常不直观,并且不方便。在读取图像的过程就是一个大问题。不同的格式,有不同的读取方法。如果利用MATLAB岂不是会方便很多?


鉴于此,网上找了找相关解决方案,最后决定自己写一个,完整一点的


先看看效果

初始界面,美化什么的就没做了


点击img2txt,弹出对话框,显示图片并写道data.txt里面

点击txt2img,选择txt文件

注意前两个数字为图像的大小

这样,直接能把图片转成可以输入modlsim的格式(注意前连个数字),在modlsim处理完成后,读到本程序中,即可显示效果

上代码

% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)[FileName,PathName] = uigetfile({'*.jpg';'*.bmp';'*.*'},'File Selector');if FileName==0    return ;endset(handles.text2,'String',FileName);axes(handles.axes1);img = imread(FileName);imshow(img);axis off[m n c]=size(img);imshow(img);if(c==3) %RGB pic    img=rgb2gray(img);end fid = fopen('data.txt','w');fprintf(fid,'%d,\t',m);fprintf(fid,'%d,\t',n);for i=1:m    for j=1:n        fprintf(fid,'%d,\t',img(i,j));    end%    fprintf(fid,'\n');  endfclose(fid);% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)[FileName,PathName] = uigetfile({'*.txt';'*.*'},'File Selector');if FileName==0    return ;endimg=load(FileName);m=img(1);n=img(2);img=reshape(img(3:end),m,n);img=img';imshow(uint8(img))


0 0
原创粉丝点击