0
 I=imread('X.jpg'); 
 [a b]=size(I);
 figure;imshow(I);
j=rgb2ycbcr(I);
figure;
imshow(j);
ca=mat2cell(j,8*ones(1,size(j,1)/8),8*ones(1,size(j,2)/8),3);
p=1; 

 for c=1:size(ca,1)
  for r=1:size(ca,2)
    subplot(8,8,p);
    imshow(ca{c,r});
    p=p+1;
    end
   end

i get the following error: Index exceeds number of subplots. Any thoughts?

rayryeng
  • 102,964
  • 22
  • 184
  • 193
matlabuser
  • 101
  • 1
  • 11

1 Answers1

1

The reason why is because you have more image blocks to show than you have subplot spaces when plotting. Change your for loop code to this instead:

p = 1;
figure;
for c=1:size(ca,1)
    for r=1:size(ca,2)
       subplot(size(ca,1),size(ca,2),p); %// Change
       imshow(ca{c,r});
       p=p+1;
    end
end

This way, you will have as many subplot spaces to plot as you have pixel blocks to show.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • That's because you need to spawn a new figure. Try doing `figure;` before the `for` loop and try again. – rayryeng Nov 22 '14 at 07:02
  • i did 2 figures before the loop and it is still empty – matlabuser Nov 22 '14 at 07:09
  • @RéaH.Rahhal It works for me.... I just tried it with a colour image myself. I ran your exact code with the modifications I made. I see an output. Make sure you load in a **colour image**. It may also help if you show us what image you're using too. – rayryeng Nov 22 '14 at 07:09
  • @RéaH.Rahhal - Yes, you spawned two figures, but you need to spawn **ANOTHER** one. Those two figures are for the original image and its YCbCr equivalent. You need **ANOTHER** one to show the decomposed blocks. – rayryeng Nov 22 '14 at 07:13
  • the original image dimensions are:<1200x1600x3 uint8>.i spawned 3 figures before the loop and i still don't get any result.i chose an image which dimensions are divisible by 8 – matlabuser Nov 22 '14 at 07:22
  • @RéaH.Rahhal - no wonder.... you're not getting a result because **it's taking too long**. Do you realize how many 8 x 8 blocks you're going to generate with that large of an image? It would also not be recommended you show all of the blocks in a single figure because there would be so many. I don't know if the MATLAB renderer can handle something like that. You're getting nothing because MATLAB is **still running in the background** to accomplish what you want. Try resizing the image so that it's smaller, then try running your code. You'll get results much faster. – rayryeng Nov 22 '14 at 07:24
  • @matlabuser - Did this code work for you? Consider accepting my answer if it did. – rayryeng Nov 26 '14 at 16:45