How to make it not to go dark?
1 view (last 30 days)
Show older comments
I use the below function:
function SliderDemo
clc
clear all
NumFrames = 15; %// Check below for dummy 4D matrix/image sequence
hFig = figure('Position',[100 100 500 500],'Units','normalized');
handles.axes1 = axes('Units','normalized','Position',[.2 .2 .6 .6]);
%// Create slider and listener object for smooth visualization
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50],'Min',1,'Max',NumFrames,'Value',1,'SliderStep',[1/NumFrames 2/NumFrames],'Callback',@XSliderCallback);
handles.SliderxListener = addlistener(handles.SliderFrame,'Value','PostSet',@XListenerCallBack);
handles.Text1 = uicontrol('Style','Text','Position',[180 420 60 30],'String','Current frame');
handles.Edit1 = uicontrol('Style','Edit','Position',[250 420 100 30],'String','1');
%// Create dummy image sequence, here 4D sequence of grayscale images.
Img = DicomReader('S0000009.dcm')
isoImage = makeImIsoRGB(Img, [1,1,15], 1.5, 'cubic')
MyImage = isoImage;
MyMatrix = MyImage;
%// Use setappdata to store the image stack and in callbacks, use getappdata to retrieve it and use it. Check the docs for the calling syntax.
setappdata(hFig,'MyMatrix',MyMatrix); %// You could use %//setappdata(0,'MyMatrix',MyMatrix) to store in the base workspace.
%// Display 1st frame
imshow(MyMatrix(:,:,1))
%// IMPORTANT. Update handles structure.
guidata(hFig,handles);
%// Listener callback, executed when you drag the slider.
function XListenerCallBack
%// Retrieve handles structure. Used to let MATLAB recognize the
%// edit box, slider and all UI components.
handles = guidata(gcf);
%// Here retrieve MyMatrix using getappdata.
MyMatrix = getappdata(hFig,'MyMatrix');
%// Get current frame
CurrentFrame = round((get(handles.SliderFrame,'Value')));
set(handles.Edit1,'String',num2str(CurrentFrame));
%// Display appropriate frame.
imshow(MyMatrix(:,:,CurrentFrame),'Parent',handles.axes1);
guidata(hFig,handles);
end
%// Slider callback; executed when the slider is release or you press
%// the arrows.
function XSliderCallback(~,~)
handles = guidata(gcf);
%// Here retrieve MyMatrix using getappdata.
MyMatrix = getappdata(hFig,'MyMatrix');
CurrentFrame = round((get(handles.SliderFrame,'Value')));
set(handles.Edit1,'String',num2str(CurrentFrame));
imshow(MyMatrix(:,:,CurrentFrame),'Parent',handles.axes1);
guidata(hFig,handles);
end
end
Although, it perfectly operates, still from Frame 1 to 15 (which is the last frame), only the first and the last frames are visible. In among the transition of the frames (2-14) they appear black/ dark, like they fade and come back again at the final frame.
Where is the wrong part? How to make it appear normal throughout the transition of all frames?
4 Comments
Jan
on 28 May 2018
by the way: A clear all on top of a function is a waste of time only. Beside deleting many useful things like loaded functions and persistent variables, clear all cleans up the current workspace. But this is empty on top of a function. Therefore clear all is "cargo cult programming".
It needs a lot of time to reload the M-files from the slow hard disk after a clear all. This can costs seconds.
We cannot run your code. Therefore it is impossible for us to debug it. But it is easy for you. Simply set some breakpoints to find out, where the observed effect happens.
It is much more efficient to run imshow once only and update the cdata afterwards.
You use a nested function and share the data using guidata. This is an overkill. One of the both methods is sufficient.
But most of all consider Rik's comment: The code does not contain command, which modify a color. This means, that the source of a color change must be somewhere else in code, you did not show.
Answers (2)
Stelios Fanourakis
on 28 May 2018
4 Comments
Image Analyst
on 28 May 2018
Can't really tell. Zip up the m file, fig file, and any data files we'd need to run this and we might give it a try.
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!