0

I want to convert all frames in my video from RGB color model to HSV color model.But I'm getting error and I couldn't solve it.Matlab code is:

obj=mmreader('C:\Users\newendo.avi');
nFrames=obj.NumberOfFrames;
for k=1:3000
    img=read(obj,k);
    [m,n] = size(img); % get size of your image
    imvector = reshape(img, m*n, 1); % reshape your image to a vector to compute DCT
    imdct = dct2(imvector); % compute DCT 
    imagedct = reshape(imdct,m,n); %reshape result back to original form of your image    

    hsv_image = rgb2hsv(imagedct) ;

     figure(1)
     imshow(img,[]);
end

ERROR is :

Attempted to access r(:,2); index out of bounds because size(r)=[921600,1,1].

Error in rgb2hsv (line 74) g = r(:,2); b = r(:,3); r = r(:,1);

Error in file2 (line 9) hsv_image = rgb2hsv(imvector);

My aim is to read the video, calculate dct and then convert to HSV model.

Help me out.

  • I tried the following but getting "Subscripted assignment dimension mismatch" error. pixels = double(cat(4,imagedct))/255; nFrames = size(pixels,4); for f = 1:nFrames pixels(:,:,:,f) = rgb2hsv(pixels(:,:,:,f)); end; – Porkodi Devi Jan 20 '15 at 11:49

1 Answers1

0

Please check that imagedct is a 3-Dimensional RGB image rather than a 2-Dimensional Grayscale image. The error might be because of that.

articuno
  • 546
  • 5
  • 12
  • 3
    This should be a comment. – Stijn Bernards Jan 20 '15 at 09:43
  • Thanks for your reply @articuno I tried the following but getting "Subscripted assignment dimension mismatch" error. pixels = double(cat(4,imagedct))/255; nFrames = size(pixels,4); for f = 1:nFrames pixels(:,:,:,f) = rgb2hsv(pixels(:,:,:,f)); end; – Porkodi Devi Jan 20 '15 at 11:46
  • Its again because the dimension of `pixels` is the same as that of `imagedct` which is not 4 I guess. – articuno Jan 21 '15 at 06:10