How can I get the result from uibuttongroup to slider?
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm doing a small image processing project that's going to submit very soon. But I still have a problem with the process. I have uibuttongroup like this:
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
global imgfile ha
ha = get(eventdata.NewValue,'Tag');
switch ha
case 'lab'
a = rgb2lab(imgfile);
axes(handles.axes2)
imshow(a(:,:,1),[0 100]);
case 'yiq'
b = rgb2ntsc(imgfile);
axes(handles.axes2)
imshow(b(:,:,1));
case 'xyz'
c = rgb2xyz(imgfile);
axes(handles.axes2)
imshow(c);
case 'none'
axes(handles.axes2)
imshow(imgfile);
end
guidata(hObject,handles);
I want to call the result (already processed image) to slider1_callback which is for adjusting brightness.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global y imlight
val = 0.5*get(hObject, 'Value')-0.5;
y = get(handles.uibuttongroup1, 'Value');
imlight = y+val;
set(handles.edit1, 'String',num2str(val));
guidata(hObject,handles);
axes(handles.axes2)
imshow(imlight);
guidata(hObject,handles);
Absolutely, I get an error after running gui and using silder. So please give me any advices so that I can finally finish this project.
Thank you.
댓글 수: 0
답변 (1개)
Geoff Hayes
2019년 12월 17일
Ploy - you haven't indicated what your error is, though it may have to do with
y = get(handles.uibuttongroup1, 'Value');
imlight = y+val;
What is y or what are you hoping y to be? I almost think that you expect it to be an image which you then add val which then you show on the axes.
If that is the case, then I would do something like the following. In your button group callback, save the image (to your handles structure) of the image that you are showing in the axes2. Then, in your slider callback, access that image and apply the brightness to it
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = 0.5*get(hObject, 'Value')-0.5;
set(handles.edit1, 'String',num2str(val));
if isfield(handles, 'newImage')
imageToShow = handles.newImage + val; % use whatever name for this image
axes(handles.axes2)
imshow(imageToShow);
end
See also https://www.mathworks.com/matlabcentral/answers/463733-matlab-gui-changing-image-brightness-using-slider for a similar example.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!