Как сохранить маркеры MATLAB в рабочей области>
Я пишу код для регистрации изображения и хочу сохранить фиксированное изображение (handles.imgFixed) и переместить изображение (handles.imgMoving) в рабочую область MATLAB. Таким образом, я планирую использовать evalin, чтобы вернуть эти переменные в графический интерфейс MATLAB для дальнейшего анализа. Вот мой код из GUI:
function uploadFixed_Callback(hObject, ~ , handles)
% hObject handle to uploadFixed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.gif; *.png; *.jpg; *.tif', 'Image Files(*.gif,*.png,*.jpg,*.tif)';'*', 'All files'}, 'File Selector');
set(handles.output,'CurrentAxes',handles.imgFixed);
handles.fixPath = strcat(pathname,filename);
hold off;
imshow(handles.fixPath);
hold on;
set( get(handles.imgFixed,'Children'),'ButtonDownFcn', {@imgFixed_ButtonDownFcn,handles});
set( get(handles.imgMoving,'Children'), 'ButtonDownFcn', {@imgMoving_ButtonDownFcn,handles});
guidata(hObject,handles);
% --- Executes on button press in uploadMoved.
function uploadMoved_Callback(hObject, eventdata, handles)
% hObject handle to uploadMoved (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname] = uigetfile({'*.gif; *.png; *.jpg; *.tif', 'Image Files (*.gif,*.png,*.jpg,*.tif'; '*', 'All Files'}, 'File Selector');
set(handles.output, 'CurrentAxes', handles.imgMoving);
handles.movePath = strcat(pathname,filename);
hold off;
imshow(handles.movePath);
hold on;
set( get(handles.imgFixed,'Children'), 'ButtonDownFcn', {@imgFixed_ButtonDownFcn,handles});
set( get(handles.imgMoving,'Children'), 'ButtonDownFcn', {@imgMoving_ButtonDownFcn,handles});
guidata(hObject,handles);
% --- Executes on mouse press over axes background.
function imgFixed_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to imgFixed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.output, 'CurrentAxes', handles.imgFixed);
imshow(handles.imgFixed);
% --- Executes on mouse press over axes background.
function imgMoving_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to imgMoving (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.output, 'CurrentAxes', handles.imgMoving);
imshow(handles.imgMoving);
Спасибо, я ценю ваше время и предложения
1 ответ
Решение
- Вы можете сохранить переменную в базовой рабочей области с помощью assignin, а затем вернуть ее обратно с помощью evalin.
assignin('base', 'imgFixed', handles.imgFixed)
- экспортирует handles.imgFixed в базовое рабочее пространство - Вы также можете назначить handles.imgFixed глобальной переменной. Таким образом, вы можете получить к нему доступ из любой другой функции.
globale imgFixed; imgFixed = handles.imgFixed;
Но я не знаю, полностью ли я понимаю ваш вопрос. Почему вы хотите хранить эти изображения в рабочей области? Что не так с ручками для передачи переменных?