0

I cannot make too big file (like tried here) so I need to show only portions at a time. However, I cannot make the transfer from one file to another smooth in Matlab. I am trying to expand the solution of the thread To refresh imshow in Matlab? for two images. The problem is the ending of image A and start of the image B. Now, I have an interruption in the flow, which I do not like because I cannot show two images at the same time without an interruption.

In the example here, it is not needed to filter the axes. Code

iterationCounter=1;

hFig=figure('Menubar','none', 'NumberTitle','off', 'Color','k');
while(iterationCounter < 7)

    filenamePng=fullfile(homedir, '/Images/Raw/', iterationCounter, '.png');

    imgRGB=imread(filenamePng);

    % https://stackoverflow.com/a/29952648/54964
    %%// create sliding-window video
    len = 40*2^3;
    signal = imgRGB(:,1:end,:);
    hImg = imshow(signal(:,1:1+len,:), ...
        'InitialMagnification',100, 'Border','tight');

    vid = VideoWriter('signal.avi');
    vid.Quality = 100;
    vid.FrameRate = 60;
    open(vid);

    M = size(signal,2);
    for k=1:M-len
        set(hImg, 'CData',signal(:,k:k+len,:))
        writeVideo(vid, getframe());
    end

    iterationCounter=iterationCounter+1;
end

close(vid);

Output for Image A and Image B

enter image description here

where there is an interruption in the slider after each image. The picture is just a screenshot of two images: beginning and ending of the slider. The blue area is just OS X GUI but still indicates that there is a gap and interruption between the start and end.


How can show/join two images simultaneously in Matlab's slider?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 1
    Where are you getting the value of `len` from? – Suever Mar 10 '16 at 18:07
  • @Suever It is just nicely selected. You can set there what you want. 40 was the standard. I started to multiply it by 2 so long as possible. I do not understand why you cannot do `40*2^4` so I found the upper limit as `40*2^3` in my case. – Léo Léopold Hertz 준영 Mar 10 '16 at 18:13
  • 1
    I guess I'm a little confused by your last Image and the significance of the blue box. – Suever Mar 10 '16 at 18:16
  • @Suever It is just a screenshot of two images in OS X. There are just the beginning of the flow and the ending of the flow. Nothing else special. I can remove it if you want. – Léo Léopold Hertz 준영 Mar 10 '16 at 18:23

2 Answers2

1

In order to display multiple images side by side in this scrolling window, I think the easiest approach is to actually load all of the images upfront into an array that is [nRows x (nColumns * nImages) x 3] and then just use the original code to scroll through this.

hFig=figure('Menubar','none', 'NumberTitle','off', 'Color','k');

signal = [];

% Load all the images into one "long" image
for k = 1:7
    filename = fullfile(homedir, sprintf('%d.png', k));
    img = imread(filename);
    signal = cat(2, signal, img);
end

%%// create sliding-window video
windowWidth = 320; % Width in pixels
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
    'InitialMagnification',100, 'Border','tight');

vid = VideoWriter('signal.avi');
vid.Quality = 100;
vid.FrameRate = 60;
open(vid);

M = size(signal,2);
for k = 1:(M - windowWidth)
    set(hImg, 'CData',signal(:,k:k + windowWidth,:))
    writeVideo(vid, getframe());
end

close(vid);
Suever
  • 64,497
  • 14
  • 82
  • 101
0

The command imagesc is a low-level image command where Suever's proposal does not work. A general approach to remove padding/margins/background is to use

<plot imshow imagesc ...>
set(gca,'position',[0 0 1 1],'units','normalized') 
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697