为什么用imread 读取100读不出图片来

扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
如何用Matlab读入并显示图片文件
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口2037人阅读
通常我们为了简单起见,是把所有的库(.lib)包括debug、release两个版本同时加载的。这样的话象下面的代码是可以正常工作的:
#include &opencv2\opencv.hpp&
#include&iostream&
void main()
IplImage *
src = cvLoadImage(&lena.jpg&); //这里将lena.jpg和lena.cpp文件放在同一个文件夹下
cvNamedWindow(&lena&,CV_WINDOW_AUTOSIZE);
cvShowImage(&lena&,src);
cvWaitKey(0);
cvDestroyWindow(&lena&);
cvReleaseImage(&src);
但是imread函数则不行,比如:
/***********************************************************************
* OpenCV 2.4.3 测试例程
* 于仕琪 提供
***********************************************************************/
#include &stdafx.h&
#include &opencv2/opencv.hpp&
int _tmain(int argc, _TCHAR* argv[])
const char* imagename = &lena.jpg&;
//从文件中读入图像
Mat img = imread(imagename);
//如果读入图像失败
if(img.empty())
fprintf(stderr, &Can not load image %s\n&, imagename);
return -1;
//显示图像
imshow(&image&, img);
//此函数等待按键,按键盘任意键就返回
waitKey();
只能是在两种模式下分别载入相应版本的.lib才行
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:56949次
排名:千里之外
原创:18篇
转载:13篇
评论:19条
(1)(7)(8)(13)(1)(1)(1)(1)&& 查看话题
MATLAB小波去噪求助(附算法和显示图片)!不知自己哪个地方出了问题,求指点!
算法(参考资料里面的算法所用的图片和图片读取方式、添加噪声算法与我不一样):
%第一部分:添加高斯噪声并显示图像
=imread('hehua.jpg');
figure,subplot(131),imshow(Y),title('原始图像');%显示原图像
X=rgb2gray(Y);%转化为灰度图像
subplot(132),imshow(X),title('灰度图像');%显示灰度图像
% 生成含噪图像并显示
% X=double(X);
M=imnoise(X,'gaussian',0,0.01);%添加均值为0,方差为0.01的高斯白噪声
subplot(133),imshow(M),title('高斯噪声图像');%显示含噪图像
wname='db2';
= dwt2(M,wname);
subplot(321); image(M); colormap(map); title('原始图像');
subplot(321); image(cA); colormap(map); title('低频系数图像');
subplot(322); image(cH); colormap(map); title('水平高频系数图像');
subplot(323); image(cV); colormap(map); title('垂直高频系数图像');
subplot(324); image(cD); colormap(map); title('对角线高频系数图像');
rX = idwt2(cA, cH, cV, cD, wname);
rA = upcoef2('a', cA, wname);
rH = upcoef2('h', cH, wname);
rV = upcoef2('v', cV, wname);
rD = upcoef2('d', cD, wname);
subplot(321); image(M); colormap(map); title('原始图像');
subplot(322); image(rX); colormap(map); title('重构图像');
subplot(323); image(rA); colormap(map); title('低频系数直接重构图像');
subplot(324); image(rH); colormap(map); title('水平高频系数直接重构图像');
subplot(325); image(rV); colormap(map); title('垂直高频系数直接重构图像');
subplot(326); image(rD); colormap(map); title('对角线高频系数直接重构图像');
自己在MATLAB上运行显示图和参考资料上的图为:
为什么中间两幅图,显示的都是空白?没有图了?一直弄不明白,不知自己算法哪个地方出问题了?就想自己改动的算法能像参考资料里面显示的一样都显示出来!谢谢
参考资料应该显示图.jpg
不是非常明白楼主的意思。我的理解是:
问题1:为什么中间两幅图,显示的都是空白?
答:你是指Figure2和Figure3的显示中,全是白色吗?这个是因为你用了colormap(map)。如果换成colormap(gray),那就有灰度图的显示了。
问题2:没有图了?
答:如果你的意思是跟上一个问题一样,那么按照上一个步骤都换成colormap(gray),那就解决了。但是,我发现你程序还有一段小错误导致 “没有图了?”
wname='db2';
= dwt2(M,wname);
subplot(321); image(M); colormap(map); title('原始图像');
subplot(321); image(cA); colormap(map); title('低频系数图像');
subplot(322); image(cH); colormap(map); title('水平高频系数图像');
subplot(323); image(cV); colormap(map); title('垂直高频系数图像');
subplot(324); image(cD); colormap(map); title('对角线高频系数图像');
这里subplot(32 是指3行2列,也就是6张图,你的编号应该参考下一段进行修改,
subplot(321); image(M); colormap(map); title('原始图像');
subplot(322); image(cA); colormap(map); title('低频系数图像');
subplot(323); image(cH); colormap(map); title('水平高频系数图像');
subplot(324); image(cV); colormap(map); title('垂直高频系数图像');
subplot(325); image(cD); colormap(map); title('对角线高频系数图像');
否则Figure2中 '原始图像' 漏掉了。
另外,运用matlab时主要的老师就是该软件提供的帮助,基本每个函数都要说明和案例。不知道我说的有没有用。 一:
因为cA,cH,... 是 double 型 变量,变换范围不是image默认的,用imshow 或image前,在workplace里看下cA,cH,...的范围
楼主可以尝试这样用,这个最方便:
figure,imhsow(cA,) ,title("低频图像的系数");
% 其中 imshow参数内的 表示输出的范围
%具体的用命令 doc imshow&&看详细介绍
楼主贴出的 subplot用法,有点小问题,出现了图像覆盖的现象,两个subplot(321)了
subplot(321); image(M); colormap(map); title('原始图像');
subplot(321); image(cA); colormap(map); title('低频系数图像'); : Originally posted by star2883 at
不是非常明白楼主的意思。我的理解是:
问题1:为什么中间两幅图,显示的都是空白?
答:你是指Figure2和Figure3的显示中,全是白色吗?这个是因为你用了colormap(map)。如果换成colormap(gray),那就有灰度图的显 ... 首先,谢谢您能热心对我的问题进行斧正,使我对自己的错误有了认识和改进!但是我还有些问题想请教您,希望能得道您的指点,谢谢!
1、下面是我按照您的建议修改后的算法:
%第一部分:添加高斯噪声并显示图像
=imread('hehua.jpg');
figure,subplot(131),imshow(Y),title('原始图像');%显示原图像
X=rgb2gray(Y);%转化为灰度图像
subplot(132),imshow(X),title('灰度图像');%显示灰度图像
% 生成含噪图像并显示
% X=double(X);
M=imnoise(X,'gaussian',0,0.01);%添加均值为0,方差为0.01的高斯白噪声
subplot(133),imshow(M),title('高斯噪声图像');%显示含噪图像
wname='db2';
= dwt2(M,wname);
subplot(321); image(M); colormap(gray); title('原始图像');
subplot(322); image(cA); colormap(gray); title('低频系数图像');
subplot(323); image(cH); colormap(gray); title('水平高频系数图像');
subplot(324); image(cV); colormap(gray); title('垂直高频系数图像');
subplot(325); image(cD); colormap(gray); title('对角线高频系数图像');
rX = idwt2(cA, cH, cV, cD, wname);
rA = upcoef2('a', cA, wname);
rH = upcoef2('h', cH, wname);
rV = upcoef2('v', cV, wname);
rD = upcoef2('d', cD, wname);
subplot(321); image(M); colormap(gray); title('原始图像');
subplot(322); image(rX); colormap(gray); title('重构图像');
subplot(323); image(rA); colormap(gray); title('低频系数直接重构图像');
subplot(324); image(rH); colormap(gray); title('水平高频系数直接重构图像');
subplot(325); image(rV); colormap(gray); title('垂直高频系数直接重构图像');
subplot(326); image(rD); colormap(gray); title('对角线高频系数直接重构图像');
2、下面figure1——figure3是修改算法运行后显示的图像。
下面是我的一些问题:
3、figure2中第一幅图“原始图像”,第二幅“低频系数图像”,为什么那么多白色像素?figure2中的“原始图像”应该是figure1中的第三幅图像,但是不知道为什么运行算法后会这样?figure3中也有同样的问题。
4、能否直接用真彩图像进行小波分解、重构、真彩显示?(我尝试过,但是基本小波分解和重构部分还是什么显示都没有,连图像标题都没有显示)。
figure1.jpg
figure2.jpg
figure3.jpg : Originally posted by skevin000 at
因为cA,cH,... 是 double 型 变量,变换范围不是image默认的,用imshow 或image前,在workplace里看下cA,cH,...的范围
楼主可以尝试这样用,这个最方便:
figure,imhsow(cA,) ,title(&低频图像的 ... 谢谢您的意见!我按照您的意见也进行了算法修改,得到了改善,下面我将我的修改算法运行结果列出来,还有几个问题想请教您,谢谢!
1、修改后的算法:
%第一部分:添加高斯噪声并显示图像
=imread('hehua.jpg');
figure,subplot(131),imshow(Y),title('原始图像');%显示原图像
X=rgb2gray(Y);%转化为灰度图像
subplot(132),imshow(X),title('灰度图像');%显示灰度图像
% 生成含噪图像并显示
% X=double(X);
M=imnoise(X,'gaussian',0,0.01);%添加均值为0,方差为0.01的高斯白噪声
subplot(133),imshow(M),title('高斯噪声图像');%显示含噪图像
wname='db2';
= dwt2(M,wname);
subplot(321); imshow(Y,); title('原始图像');
subplot(322); imshow(cA,); title('低频系数图像');
subplot(323); imshow(cH,); title('水平高频系数图像');
subplot(324); imshow(cV,); title('垂直高频系数图像');
subplot(325); imshow(cD,); title('对角线高频系数图像');
rX = idwt2(cA, cH, cV, cD, wname);
rA = upcoef2('a', cA, wname);
rH = upcoef2('h', cH, wname);
rV = upcoef2('v', cV, wname);
rD = upcoef2('d', cD, wname);
subplot(321); imshow(M,); title('原始图像');
subplot(322); imshow(rX,); title('重构图像');
subplot(323); imshow(rA,); title('低频系数直接重构图像');
subplot(324); imshow(rH,); title('水平高频系数直接重构图像');
subplot(325); imshow(rV,); title('垂直高频系数直接重构图像');
subplot(326); imshow(rD,); title('对角线高频系数直接重构图像');
2、下面是修改算法运行后的图(figure1——figure4):
3、我的问题:
(1)您指出的double和uint8,我通过workspace,发现:输入真彩图像和灰度图像、加噪图像都是uint8型,小波分解后的低频和高频系数都是double型,难道需要在小波分解之前(加噪处理之后)就要先转换成double型吗?小波重构后显示重构图像是否需要再转换成uint8型?
(2)imshow(M,),改动后,有灰度图像显示,这个函数是不是要显示uint8型数据图像?
(3)我把算法中的rgb2gray算法去噪,我想让figure1——figure4都显示彩色图像,但是显示有问题,算法运行后图像分别为figure5——figure7;怎么样才能彩色显示?我想看的更直观些。
figure1.jpg
figure2.jpg
figure3.jpg
figure4.jpg
figure5.jpg
figure6.jpg
figure7.jpg : Originally posted by skevin000 at
因为cA,cH,... 是 double 型 变量,变换范围不是image默认的,用imshow 或image前,在workplace里看下cA,cH,...的范围
楼主可以尝试这样用,这个最方便:
figure,imhsow(cA,) ,title(&低频图像的 ... 这位同学,关于你的问题,我建议你查一下matlab下的dwt2函数的帮助,其中包含一个例子应该就是你所想要的。
我贴一段代码,你看了就知道了
Single-level discrete 2-D wavelet transform
= dwt2(X,'wname')
= dwt2(X,Lo_D,Hi_D)
Description
The dwt2 command performs a single-level two-dimensional wavelet decomposition with respect to either a particular wavelet ('wname', see wfilters for more information) or particular wavelet decomposition filters (Lo_D and Hi_D) you specify.
= dwt2(X,'wname') computes the approximation coefficients matrix cA and details coefficients matrices cH, cV, and cD (horizontal, vertical, and diagonal, respectively), obtained by wavelet decomposition of the input matrix X. The 'wname' string contains the wavelet name.
= dwt2(X,Lo_D,Hi_D) computes the two-dimensional wavelet decomposition as above, based on wavelet decomposition filters that you specify. Lo_D is the decomposition low-pass filter. Hi_D is the decomposition high-pass filter.
Lo_D and Hi_D must be the same length.
Let sx = size(X) and lf = t then size(cA) = size(cH) = size(cV) = size(cD) = sa where sa = ceil(sx/2), if the DWT extension mode is set to symmetric padding. For the other extension modes, sa = floor((sx+lf-1)/2).
For information about the different Discrete Wavelet Transform extension modes, see dwtmode.
= dwt2(...,'mode',MODE) computes the wavelet decomposition with the extension mode MODE that you specify.
MODE is a string containing the desired extension mode.
An example of valid use is
= dwt2(x,'db1','mode','sym');
When X represents an indexed image, then X, as well as the output arrays cA,cH,cV,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.
For more information on image formats, see the image and imfinfo reference pages.
% The current extension mode is zero-padding (see dwtmode).
% Load original image.
% X contains the loaded image.
% map contains the loaded colormap.
nbcol = size(map,1);
% Perform single-level decomposition
% of X using db1.
= dwt2(X,'db1');
% Images coding.
cod_X = wcodemat(X,nbcol);
cod_cA1 = wcodemat(cA1,nbcol);
cod_cH1 = wcodemat(cH1,nbcol);
cod_cV1 = wcodemat(cV1,nbcol);
cod_cD1 = wcodemat(cD1,nbcol);
% Using some plotting commands,
% the following figure is generated. : Originally posted by Allen2014 at
谢谢您的意见!我按照您的意见也进行了算法修改,得到了改善,下面我将我的修改算法运行结果列出来,还有几个问题想请教您,谢谢!
1、修改后的算法:
%第一部分:添加高斯噪声并显示图像
=imread ... 回复(个人看法)
(1)小波变换前是要将uint8转换成double型的,如果小波函数内部有自动转换的,也可以不转的。重构之后的double 型可以按照 类似于 *255 这样的公式来转换后,在转为uint8,就是最常见的图片的表达方式了0~255,当然也可以转成其它灰度级别的
(2)整形和double的都可以的。imshow(M,),的意思将可以理解为将图像灰度的最小值作为灰度0,最大值作为255,就类似于增强了图像的对比度。可能说的不够清楚,看matlab的帮助文档吧&&help imshow 或doc imshow
(3)一般彩色图像及部分灰度图像,都是按照RGB(红、绿、蓝)模型来表达色彩的,你如果要对彩色图像进行去噪,我觉得有下面两种方法:1)分别对RGB的三个分量进行滤波,2)将RGB转换为HSI模型,对考虑是分别对是三个分量滤波,还是只对H分量滤波。这些都是很基本的知识,找一本数字图像处理书好好看看吧 : Originally posted by star2883 at
这位同学,关于你的问题,我建议你查一下matlab下的dwt2函数的帮助,其中包含一个例子应该就是你所想要的。
我贴一段代码,你看了就知道了
Single-level discrete 2-D wavelet transfo ... 谢谢您!我现在明白了些! : Originally posted by skevin000 at
回复(个人看法)
(1)小波变换前是要将uint8转换成double型的,如果小波函数内部有自动转换的,也可以不转的。重构之后的double 型可以按照 类似于 *255 这样的公式来转换后,在转为uint8,就是最常见的图片的表 ... 谢谢!我也是刚刚接触图像处理! clear all& && && && &&&%删除变量
close all& && && && &&&%关闭窗口
clc& && && && && && &%清除窗口
i=imread('biyesheji.jpg');& && && &%输入图像
x=i(:,:,1);& && && && && && && && &&&%三维转换为二维
subplot(221);& && && && && && && & %新建窗口
imshow(x);& && && && && && && && && && &%显示图像
title('原始图像');& && && && && && && &&&%设置图像标题
& && && && && && && &&&%设置显示比例,生成含噪图像并图示
xx=imnoise(x,'salt & pepper',0.02);& && && &%给图像加椒盐噪声& && &
subplot(222);& && && && && && & %新建窗口
imshow(xx);& && && && && && && &%显示图像
title('含噪图像');& && && && &&&%设置图像标题
x11=medfilt2(xx,);& &&&
x12=double(x11);
=size(x12);
=wavedec2(x12,3,'coif2');&&
n=;& && && && && &
p4=0.02*(sqrt(2*log(a*b)));
size(detcoef2('h',c,s,1));&&
size(detcoef2('v',c,s,1));
size(detcoef2('d',c,s,1));
p1(1)=detcoef2('h',c,s,1);
p2(1)=detcoef2('v',c,s,1);
p3(1)=detcoef2('d',c,s,1);
p1(2)=detcoef2('h',c,s,2);& && &
p2(2)=detcoef2('v',c,s,2);
p3(2)=detcoef2('d',c,s,2);
for i=1:1:2& && && && &&&
& &p1(i)=1/((p1(i)-p4)^2+1);&&
& &&&if p1(i)>=p4& && && && && && &
& && &p1(i)=sign(p1(i))*(abs(p1(i))-p1(i)*p4);
& &&&if p2(i)>=p4
& && &p2(i)=sign(p2(i))*(abs(p2(i))-p2(i)*p4);
& &if p3(i)>=p4
& && &p3(i)=sign(p3(i))*(abs(p3(i))-p3(i)*p4);
nc=wthcoef2('h',c,s,n,p,'s') ;
nc=wthcoef2('v',c,s,n,p,'s') ;
nc=wthcoef2('d',c,s,n,p,'s') ;
mc=wthcoef2('h',nc,s,n,p,'s') ;
mc=wthcoef2('v',nc,s,n,p,'s') ;
mc=wthcoef2('d',nc,s,n,p,'s') ;
x3=waverac2(mc,s,'coif2');
x3=uint8(x3);
subplot(223);& && && && && && & %新建窗口
image(x3);& && && && && && && && && &%显示图像
title('第一次消噪后的图像');& && && && && &%设置图像标题
这个程序哪里错了呢matlab imread读图片问题??_百度知道
matlab imread读图片问题??
imread有没有什么办法读取a.jpg,这里面a是一个变量,例如,我输入a=5,那么就读取5.jpg这个图片。图片都在matlab目录里。
提问者采纳
strcat和num2str的联合使用 即可:a=5;imread(which(strcat(num2str(a),'.jpg')))
提问者评价
谢谢大家解答,问题解决了,第一个回答很符合我的要求,谢谢了。
其他类似问题
为您推荐:
其他3条回答
可以啊,应用下面的语句:a=input('请输入a的值:');a=num2str(a);b=strcat(a,'.jpg');[X,map]=imread(b);image(X);colormap(map);
[filename, pathname] = uigetfile('*.jpg');%filename为文件名,pathname为路径名。%若图片都在matlab目录里x=imread(filename);imshow(x)
可以的。。 所以可以遍历文件夹中的文件
imread的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁VS2010 调用OpenCV的imread读不出图片
一个很简单的功能实现,用来测试的
之前一直这么写都没问题,这次忽然读不出图片了
int main()
Mat inputI
inputImg = imread(&1.jpg&,1);
imshow(&1&,&span style=&font-family: Arial, Helvetica, sans-&&inputImg &/span&&span style=&font-family: Arial, Helvetica, sans-&&);&/span&
waitKey(0);
inputImg中显示为0,仔细检查opencv路径的配置也没有错,编译也不报错,就是读不进去图片
后来发现问题在于:
配置opencv的dll问题,
比如:程序运行的是debug,但是opencv的dll配置确实release,
或者程序运行的是release,但是opencv的dll配置确实debug
。。。。还是粗心啊。。。。
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:19791次
排名:千里之外
原创:73篇
转载:34篇
评论:13条
(5)(7)(5)(1)(20)(16)(7)(13)(2)(7)(12)(5)(2)(1)(2)(3)(1)

我要回帖

更多关于 imread 读取100 的文章

 

随机推荐