getframe produces greater image

4 visualizzazioni (ultimi 30 giorni)
Adrian
Adrian il 29 Ago 2013
Hello,
I am using getframe() to read out axes that show an image. For example an 120x90 image. But the image I get from the getframe() function has a size of 121x91. There is a small white border. How can I turn that off? Btw I am showing the image without axis.

Risposta accettata

Jan
Jan il 29 Ago 2013
Modificato: Jan il 29 Ago 2013
I do not understand your explanations. What is "the number of the current frame"? You cannot store a number "in a handle", because a handle is a kind of pointer to a HG object and created by Matlab. You mean a struct called "handle", but this is a confusing formulation. What do you think is stored in handle.frame_xy?
Again, please show us the code. It sounds like you forgot to store the modified handles struct. Then this might help:
function TheButtonCallback(hObject, EventData)
handles = guidata(hObject); % Get handles struct from figure
handles.frame_xy = how ever you obtain it
guidata(hObject, handles); % Store modified struct in the figure
Then the modified handles struct can be obtained by guidata again. If this is your problem, sharing data between callbacks is your main problem, and the extremely confusing decision of TMW to call the struct for storing figure related information "handles". Use the Search field of this forum and look form "share gui" to find many related threads: http://www.mathworks.com/matlabcentral/answers/?term=share+gui
  3 Commenti
Jan
Jan il 29 Ago 2013
These are only parts of the code and if the complete code contains the necessary further commands, everything is fine. But you do not show us the additional lines, such that we must guess, what is missing.
Please post the complete relevant part of the code.
Running a while loop, which does not perform anything, is a waste of time. If actions are triggered by the callback of another button, you can omit the loop completely and insert the action in the callback.
Adrian
Adrian il 29 Ago 2013
Modificato: Adrian il 29 Ago 2013
it is the whole code and the
handles = guidata(hObject); % Get handles struct from figure
command is missing, thats why the loop never ends and the counter doesn't work. Thank you Jan Simon and Image Analyst!!
while handles.counter < 3;
set(handles.text1, 'string', num2str(handles.counter));
drawnow;
handles = guidata(hObject);
end
set(handles.text2, 'string', 'ende');

Accedi per commentare.

Più risposte (2)

Image Analyst
Image Analyst il 29 Ago 2013
Just get the image itself, like what you put into the axes when you called image(), imshow(), or imagesc(). I mean, you have it, since you put it in there, right?
  9 Commenti
Jan
Jan il 29 Ago 2013
See my answer.
Image Analyst
Image Analyst il 29 Ago 2013
You need to call guidata immeidately after you attach/update handles.frame_xy, otherwise anything you attached to handle inside your function with the loop will not be available in it's current/updated form to the function with the button that saves the current image to disk.

Accedi per commentare.


Adrian
Adrian il 29 Ago 2013
Modificato: Adrian il 29 Ago 2013
Here is a part of the function with the loop:
for count = 1:videoObj.NumberOfFrames
handles.count=count;
start = clock;
imshow(handles.mov(count).cdata, 'parent', handles.LiveCam_axes);
drawnow
guidata(hObject, handles);
time = etime(clock, start);
while (time < 1/FrameRate)
time = etime(clock, start);
end
end
And here is the interesting part of the callback that interrupts the loop:
handles.Snapshot1 = handles.mov(handles.count).cdata;
imshow(handles.Snapshot1, 'parent', handles.Snapshot1_axes);
handles.Snapshot1 gets lost if the callback function is completed and the loop continiues.
  3 Commenti
Adrian
Adrian il 29 Ago 2013
Modificato: Adrian il 29 Ago 2013
Could you give me an example how that would look like for one of your two options.
Jan
Jan il 29 Ago 2013
Modificato: Jan il 29 Ago 2013
while (time < 1/FrameRate), time = etime(clock, start); end is a brute waste of time. A timer would be smarter and more flexible.
As I have written already: If you want to share the handles struct with other callback, store it by guidata:
handles.count=count;
guidata(hObject, handles);
...
Then you can obtain the current value by:
handles = guidata(hObject);
The problem is that the updated handles struct is contained in the local copy in the workspace of the corresponding function. But each function, here each callback, has its own workspace and changes in one workspace do not propagate magically to others.
Please take the time and follow my suggestion to search in the forum for methods to share variables between callbacks. It has been discussed such often, that it is worth to use the history of this forum instead of asking new questions.

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by