Matlab错误不支持的图像数据类型'struct'

时间:2011-04-29 18:40:23

标签: matlab

目前我正在使用matlab进行图像处理项目,我很简单地使用我的网络摄像头捕获图像,保存它,使用霍夫变换处理图像,然后尝试保存它。当我在转换后的图像上使用imwrite函数时,我得到了这个错误:

??? Error using ==> imwrite>validateSizes at 596
Unsupported image datatype 'struct'.

Error in ==> imwrite at 422
validateSizes(data);

Error in ==> findLine at 48
imwrite(tapes,fullImageFileName2);

我真的不知道这里发生了什么,但我在网络摄像头拍摄图像时使用了imwrite功能,并且没有任何错误。这是我第二次尝试保存图像,这是转换后的图像,我得到了这个错误。任何想法?

到目前为止,这是我的代码:

vidobj = videoinput('winvideo');
preview(vidobj);
pause(10);
snapshot = getsnapshot(vidobj);
fullImageFileName = fullfile(pwd, 'line.jpg');
imwrite(snapshot,fullImageFileName);
imagesc(snapshot);
imshow(snapshot);

%Load image
tape = imread('C:\Users\Mustafa\Documents\MATLAB\line.jpg');
%Displays the valid values for the Image Processing
iptsetpref ImshowBorder tight
imshow(tape)

%Segment by thresh holding
thresh1 = 100;
tapes = im2bw(tape, thresh1/255);
imshow(tapes)

%Clean up image
%Morphology to assist segmentation
tapes = bwareaopen(tapes,100);%area under 100 pixels
imshow(tapes)

%Clear objects touching the line
%suppresses structures that are lighter than their surroundings and that are connected        to the image border. 
%(In other words, use this function to clear the image border.)
%tapes = imclearborder(tapes, 26);
%imshow(tapes)

%Find tape
%Find all connected regions
[B,L] = bwboundaries(tapes, 'noholes');
numRegions = max(L(:));
imshow(label2rgb(L))


%Hough transform
[H, theta, rho] = hough(tapes);
peaks = houghpeaks(H, 2);
tapes = houghlines(tapes, theta, rho, peaks, 'FillGap', 50, 'MinLength', 30);



fullImageFileName2 = fullfile(pwd, 'linedetect.png');
imwrite(tapes,fullImageFileName2,'BitDepth',16);

1 个答案:

答案 0 :(得分:1)

houghlines返回struct。输入help houghlines以更全面地了解输出结果。

(提示,这不是图像。)

houghlines帮助页面的底部,它给出了一个如何处理输出的示例。