0

Currently I am working on matlab for an image processing project and I am simpley capturing an image with my webcam, saving it, processing the image using the hough transform and then trying to save it. When I use the imwrite function on the transformed image I get this error:

??? 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);

I dont really know whats going on here but I use the imwrite function when the image is first taken by the webcam and That saves with no errors. Its the second time I try to save an image, which is the transformed image I get this error. Anyone any ideas?

This is my code so far:

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);
4
  • 1
    We need more information, can you type whos tapes and report what it says. (It looks like tapes is a struct, so would also be good to show how you creates tapes.) Commented Apr 29, 2011 at 18:52
  • I have updated my code above, Commented Apr 29, 2011 at 18:58
  • tapes = houghlines(tapes, theta, rho, peaks, 'FillGap', 50, 'MinLength', 30); Commented Apr 29, 2011 at 18:58
  • after typing 'whos tapes', this is what I get: >> whos tapes Name Size Bytes Class Attributes tapes 1x3 1120 struct Commented Apr 29, 2011 at 19:00

1 Answer 1

1

houghlines returns a struct. Type help houghlines to understand what the output is more thoroughly.

(Hint, it's not an image.)

At the bottom of the help page for houghlines it gives an example of what do do with the output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.