Showing multiple images with subplot and subimage in matlab

I am using a bilateral filter to process an image and I want to print the filtered images, resulting from changing the parameters, in one "box". This is the script I am running to call the filter and print the images, the results are horrible, it prints the full image and then a subplot with a really small picture that you can not tell anything. Can someone tell me what am I doing wrong in the subplot/subimage command?

```I = im2double(imread('cat.jpg'));
sig_d = 1;
sig_r = 10;
for i=1:10
sig_d = i;
for j=1:10
sig_r = 10*j;
J = bilateral(I,sig_d,sig_r);
figure,subplot(10,10,j), subimage(J);
end
end
```

I am aiming for a 10x10 block and each image in it to be distinctive and not similar to a dot. Is it possible to be done?

1) You are creating multiple figures at each stage of the inner loop; you only want (I suppose) one figure, so you need to put the command figure outside of your nested loop.

2) Your call to subplot will never fill up the entire array

subplot(10,10,j) creates a 10 by 10 array of subplots within a figure, and sets the current axes to number j. Therefore if you want to fill a figure with a 10 x 10 array of images, you need to call subplot(10,10,1) through subplot(10,10,100) in order.

Another possible way of doing this, if your output image J is always the same size, is to pre-allocate a single matrix of the correct size and use montage. e.g. :

Before the loop, preallocate:

```I2 = zeros(n,m,1,100); % n and m are the size of the output image J
```

Inside the loop, assign output to preallocated matrix

```I2(:,:,:,z) = J; % z is your counter from 1 to 100
```

Afterwards, display montage

```montage(I2,'Size',[10 10]);
```

This also has the advantage that you aren't throwing away your J each time you calculate it - so if you want to experiment with how to display the output, you can.

First of all, remove the call to figure. This opens a new window each time. Your images will also overwrite one another because subplot counts the subplots (in this case, 100) and uses the 3rd argument to determine the subplot to draw into. Your code will draw into the topmost row only. To fix that, use subplot(10,10,(i-1)*10+j), this will take your i(row in this case) into account. If you want to display your images columwise instead, use subplot(10,10,(j-1)*10+i).

As for the size of the images, there's really not much you can do. If you want to display them in a 10x10 grid, there will be 100 images on one screen, so each of them has to be rather small.