MATLAB Answers

How can I get the result from uibuttongroup to slider?

9 ビュー (過去 30 日間)
Ploy Rm
Ploy Rm 2019 年 12 月 16 日
回答済み: Geoff Hayes 2019 年 12 月 17 日
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 件のコメント

サインイン to comment.

回答 (1 件)

Geoff Hayes
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

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

タグ


Translated by