Aakash Anuj
Aakash Anuj

Reputation: 3871

Getting an imscollpanel as a subplot along with another image

I a trying to generate a view in which I have an image on the top, and below I have a set of images, which are horizontally scrollable.

For displaying the set of images, I concatenate them into a single image horizontally and then display it.

I am able to display both of these figures separately, but when I try to merge them into a single figure(which has one figure on top and a scrollable view at the bottom), this code does not do the job. Instead, it just gives me the top figure(as I want) and the bottom image(without the scrollbar, which is not what I want). How do I get the scrollbar into the bottom image?

Here is what I tried(test3.png is what I want to display at the top and the images array is what I want at the bottom with a horizontal scroll):

hFig = figure('Toolbar','none','Menubar','none');
images{1} = imread('test1.png');
images{2} = imread('test2.png');
images{3} = imread('test1.png');
images{4} = imread('test2.png');
images{5} = imread('test1.png');
images{6} = imread('test2.png');
images{7} = imread('test1.png');
images{8} = imread('test2.png');
im = cat(2,images{:});
hIm = imshow(im);
hSP = imscrollpanel(hFig,hIm);

newFig = figure;
newhIm = imshow('test3.png');

figure;
subplot(2,1,1);
imshow('test3.png')
subplot(2,1,2);
imshow(getimage(hSP))

Any help would be appreciated.

Upvotes: 1

Views: 236

Answers (2)

Benoit_11
Benoit_11

Reputation: 13945

Here is a way to do it. The trick is based from this answer and consists in creating a uipanel in which to add an axes where you can create the scrollpanel.

Adapted for your scenario, here is how it looks like:

clear
clc

%// Read demo images and create cell array.
a = imread('peppers.png');
a1 = a(:,:,1);
b = rgb2gray(imread('peppers.png'));

images{1} = a1;
images{2} = b;
images{3} = a1;
images{4} = b;
images{5} = a1;
images{6} = b;
images{7} = a1;
images{8} = b;
im = cat(2,images{:});

hf=figure; 

%// 1st subplot
hs1 = subplot(2,1,1);
imshow(a);

%// Create uipanel and place it below current image/subplot 1

hPanel= uipanel('Units','Normalized');

% Set the uipanel position to where the image is desired to be displayed.

set(hPanel,'position',[.05 0 .9 .5]);

%// Create an axes whose parent is the uipanel.
ax1 = axes('parent',hPanel,'position',[0 0 1 1],'Units','normalized');

%// Display image to get the handle.
him1 = imshow(im,'parent',ax1);

% Create the scroll panel
hSP = imscrollpanel(hPanel,him1); 

Output:

enter image description here

You can fine-tune the position of the axes...but that should get you started. Good luck!

Upvotes: 2

scmg
scmg

Reputation: 1894

You need something like "add scrollbar to axis" to make it work with subplot. Hope this helps ...

Upvotes: 0

Related Questions