Unable to save changes in images while using Slider in GUI

1 view (last 30 days)
Hi,
I am building a GUI for image analysis. When I click Load Image, all the images in the folder is displayed in Axes1. When I click Segment, all the images shown in Axes 1 are segmented and the results are shown together in Axes 2. I am using Slider, to browser through the images one by one and their corresponding segmentation results are displayed in Axes 2. I am using the Correction button to manually define my ROI in Axes 1. The corrected segmentation result would be displayed in Axes 2. The problem is that the updated images are not saved when I use the slider. For example, if I browser through the 4 th image by the slider and use the correction option, the new result would be displayed in Axes 2. However, if I browse through the 5th image and then go back to the 4 th image using the slider, the new result of the 4th image is not saved and the original segmentation result is shown in Axes 2. I am unable to save the updated result and display it in Axes 2 if come back to that 4th image using the slider. The pushbutton3 _ Callback refers to the callback when I press the Correction button. Any suggestions would be appreciated.
function imageSlider_Callback(hObject, eventdata, handles)
% hObject handle to imageSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles = guidata(hObject);
maxNumberOfImages = handles.num_files;
orig_imgs = handles.InputImage;
output_img=handles.seg;
set(hObject, 'Min', 0);
set(hObject, 'Max', maxNumberOfImages);
set(hObject, 'SliderStep', [1/maxNumberOfImages , 10/maxNumberOfImages ]);
value = int32(get(hObject,'Value'));
if value == 0 || maxNumberOfImages == 1
value = 1;
elseif value > maxNumberOfImages
value = maxNumberOfImages;
end
handles.value = value;
guidata(hObject,handles);
%% display
imshow(orig_imgs{value},...
'InitialMagnification','fit','Parent', handles.axes1);
imshow(output_img{value},...
'InitialMagnification','fit','Parent', handles.axes2);
end
% --- Executes during object creation, after setting all properties.
function imageSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to imageSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
end
% --- Executes on selection change in listbox.
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
value=handles.value;
corr_image = handles.InputImage;
hr=corr_image{value};
[MM,rect] = imcrop(hr);
MM=rgb2gray(MM);
imshow(MM,'parent',handles.axes1);
% figure,imshow(MM)
[x,y]=getpts(handles.axes1);x=round(x);y=round(y);
% x=300; y=340;
a=imgaussfilt(MM,2);
b=adapthisteq(a);
m=regiongrowing_MLT(b,x,y,12);
m=imfill(m,'holes');
% figure,imshow(m)
bw=imbinarize(m);
bw=bwareafilt(bw,1);
% figure,imshow(bw)
I = imresize(MM,.5); %-- make image smaller
m1 = imresize(bw,.5); % for fast computation
seg1 = region_seg(I, m1, 30); %-- Run segmentation
imwrite(seg1,'newimage.jpg');
imshow(seg1,'parent',handles.axes2);
handles.seg1=seg1;
guidata(hObject, handles);
end

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!