Hello
I am making image browser and I have problem with button Next Page everytime when I press button next page I want to show next 12 images and I am using this code:
for j = (jj+1) : (2*jj)
[I cmap] = imread(img(j),'frames','all');
ax=subplot(4,3,(j-12));
image(I);
colormap(ax,cmap);
axis off;
axis image;
end
where jj=12 first is showen 12 images and pressing Next Page button there should be displayed next 12. This code works when I press button Next Page first time after I run GUI but it doesn't work when I hit it second or third time...What should I do to display 12 new images every time I hit button Next Page
Thank you!

 Réponse acceptée

Image Analyst
Image Analyst le 30 Déc 2014

0 votes

What is img(j)? How is that a color or black and white image? It should be a filename string.

6 commentaires

Image Analyst
Image Analyst le 30 Déc 2014
And I'm not seeing the 'frames' option for imread() listed in the documentation.
Lolipop
Lolipop le 30 Déc 2014
Modifié(e) : Lolipop le 30 Déc 2014
function NextPage_Callback(hObject, eventdata, handles)
% hObject handle to NextPage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global img
global jj
global path
for j=(jj+1):(2*jj)
[I cmap] = imread(strcat(path,img(j).name),'frames','all');
ax=subplot(4,3,(j-12));
image(I);
colormap(ax,cmap);
axis off;
axis image;
end
Where img.name(j) are the names of images that should be displayed This code is working only for the first next page so when I press button Next Page it really displays next 12 images but the problem is when I try to press it again to display second next page there it doesn't work
Image Analyst
Image Analyst le 30 Déc 2014
Modifié(e) : Image Analyst le 30 Déc 2014
I think it's working, it's just displaying the same 12 images as the first time though. Try adding
jj = jj + 12;
after the end of the loop so that it will take the next 12 images the next time it comes in to this callback.
Instead of
ax=subplot(4,3,(j-12));
you might need this
ax=subplot(4,3, mod(j,12)+1);
Lolipop
Lolipop le 30 Déc 2014
Woow..it's working thank you sooo much
Lolipop
Lolipop le 30 Déc 2014
How is that a color or black and white image? I don't get this... should I use colormap or what?
Image Analyst
Image Analyst le 30 Déc 2014
Not sure what you're asking. If it's a color image you can't use a colormap - it does not apply. If it's an indexed image then the colormap is probably stored along with the image and you can ask imread() for it and apply it. If it's a grayscale image, you can use the gray(256) colormap (the default if you display it with imshow() but not for image() or imagesc()), or you can apply some other one if you want, such as jet(256) or parula(256) or whatever.

Connectez-vous pour commenter.

Plus de réponses (2)

Sean de Wolski
Sean de Wolski le 30 Déc 2014

0 votes

I probably doesn't remember what j is.
Put a breakpoint on the line that isn't working, run it, and see what the variables are as you press the button.

3 commentaires

Lolipop
Lolipop le 30 Déc 2014
This is working when I press Next Page first time but when I press second time it doesn't work... I thought that every time when I press push button that for loop would execute
So put a break point on the imread line. Press next page, step through, is what you expect to happen, happening? If not, why not? If so, press it again and repeat until you see a discrepancy between expectations and reality.
web(fullfile(docroot, 'matlab/matlab_prog/debugging-process-and-features.html'))
Working your way through this might be worth your time.
Lolipop
Lolipop le 30 Déc 2014
Thank you Sean de Wolski for helping me and this debugger could be really useful :)

Connectez-vous pour commenter.

Sean de Wolski
Sean de Wolski le 30 Déc 2014
Modifié(e) : Sean de Wolski le 30 Déc 2014

0 votes

probably
(j-12);
Which will not always be 1:12. Instead:
count = 0;
for j = jj:etc
count = count+1;
subplot(3,4,count)
etc.
end
NOTE with the debugger you would be able to walk through and see what each thing is on each step to avoid guessing.

Community Treasure Hunt

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

Start Hunting!

Translated by