How to display images from a cell array?

I have 5 images in a cell array 'imageshares' and I want to display them individually.
figure
image(imageshares{i}));
I used the above code and obviously this didn't work. How do I display the images?

4 commentaires

Stephen23
Stephen23 le 31 Mai 2017
Modifié(e) : Stephen23 le 31 Mai 2017
"I used the above code and obviously this didn't work"
Not much is obvious. Did you out that code in a loop of some kind, or is that the entirety of the code? What were you expecting, and what actually occurred?
fiona rozario
fiona rozario le 31 Mai 2017
Modifié(e) : fiona rozario le 31 Mai 2017
I got the following error and a blank figure window popped up:
Subscript indices must either be real positive integers or logicals.
Error in nsharestest (line 39)
image(imageshares{i});
I was expecting 5 windows to show me 5 images. It is in a for i=1:N loop.
Matthew Eicholtz
Matthew Eicholtz le 31 Mai 2017
It would be helpful to see more of your code so we can properly diagnose the problem.
f=imread('test2.jpg');
red=f(:,:,1);
green=f(:,:,2);
blue=f(:,:,3);
[r,c,d]=size(f);
shred=zeros(r,c);
shgreen=zeros(r,c);
shblue=zeros(r,c);
image=zeros(r,c);
N = input('Number of pieces to break into ');
rowgroups = diff( round(linspace(0,r,N+1)));
rshares = mat2cell(red, rowgroups, size(red,2));
gshares = mat2cell(green, rowgroups, size(green,2));
bshares = mat2cell(blue, rowgroups, size(blue,2));
imageshares=mat2cell(image, rowgroups, size(image,2));
shredshares = mat2cell(shred, rowgroups, size(shred,2));
shgreenshares = mat2cell(shgreen, rowgroups, size(shgreen,2));
shblueshares = mat2cell(shblue, rowgroups, size(shblue,2));
for i=1:N
imageshares{i}=cat(3,rshares{i},gshares{i},bshares{i});
figure
image(imageshares{i});
end

Connectez-vous pour commenter.

Réponses (2)

Star Strider
Star Strider le 31 Mai 2017
The subscript error is puzzling if ‘i=1:N’. One option is to change the loop counter variable to ‘k’ instead, since a few versions back, ‘i’ could default to the imaginary operator.
The imshow function could be a preferable option (with the index variable change):
figure
imshow(imageshares{k})
This is a guess on my part. If I guessed wrong, I will delete this Answer.
Image Analyst
Image Analyst le 1 Juin 2017
image is a built in function. Thus, this makes no sense:
imageshares=mat2cell(image, rowgroups, size(image,2));
and I don't know what you're doing with all that "shares" stuff. You read in one image, which has 3 color channels, so exactly what 5 images are you expecting to see?

2 commentaires

fiona rozario
fiona rozario le 1 Juin 2017
I entered the value of N as 5, which is the number of parts the matrix needs to be divided into. I need to divide the RGB components into parts or shares and then combine the individual components to form 5 images.
I changed the 'image' variable name and still got the same error.
Image Analyst
Image Analyst le 1 Juin 2017
To split up an image into tiles: see the FAQ

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by