Refresh Image when dragging slider

2 views (last 30 days)
Zhi kai
Zhi kai on 1 Dec 2014
Dear MATLAB community. I am creating a app for noise filtering. I'm currently having trouble in using the sliders. The image doesn't refresh even after releasing the mouse click. Here's my code:
% --- Executes on button press in Upload.
function Upload_Callback(hObject, eventdata, handles)
global im
[path,user_cance] = imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im = imread(path);
axes (handles.OriginalAx);
imshow(im);
% --- Executes on button press in grayscale.
function grayscale_Callback(hObject, eventdata, handles)
global im
axes (handles.FiltAx);
im = rgb2gray(im);
imshow(im);
% --- Executes when selected object is changed in uipanel9.
function uipanel9_SelectionChangeFcn(hObject, eventdata, handles)
global im
global output
global winSize
radiobuttons = get(eventdata.NewValue, 'Tag');
winSize = floor(get(handles.WinSize,'Value'));
Order = get(handles.butterworthOrder,'Value');
radius = get(handles.radius,'Value');
switch radiobuttons
case 'mean'
axes (handles.FiltAx);
H = fspecial('average',winSize);
F = imfilter(im,H);
output = F;
output = uint8(output);
imshow(output);
case 'median'
axes (handles.FiltAx);
F = medfilt2(im,[winSize winSize]);
output = F;
output = uint8(output);
imshow(output);
case 'max'
axes (handles.FiltAx);
x = winSize.*winSize;
B = ordfilt2(im,x,true(winSize));
output = B;
output = uint8(output);
imshow(output);
case 'min'
axes (handles.FiltAx);
B = ordfilt2(im,1,true(winSize));
output = B;
output = uint8(output);
imshow(output);
case 'butterworthHigh'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fftshift(fft2(im,PQ(1),PQ(2)));
H = 1-lpfilter('btw',PQ(1),PQ(2),radius,Order);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1),1:size(im,2));
output = uint8(g);
imshow(output);
case 'gaussianHigh'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fftshift(fft2(im,PQ(1),PQ(2)));
H = 1-lpfilter('gaussian',PQ(1),PQ(2),radius);
G = H.*F;
G =ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1),1:size(im,2));
output = uint8(g);
imshow(output);
case 'idealHigh'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = lpfilter('ideal', PQ(1), PQ(2), radius);
H = 1 - H;
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'gaussianLow'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fftshift(fft2(im,PQ(1),PQ(2)));
H =lpfilter('gaussian',PQ(1),PQ(2),radius);
G = H.*F;
G=ifftshift(G);
g = real(ifft2(G));
g= g(1:size(im,1),1:size(im,2));
output = uint8(g);
imshow(output);
case 'butterworthLow'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = lpfilter('btw', PQ(1), PQ(2), radius, Order);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'idealLow'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = lpfilter('ideal', PQ(1), PQ(2), radius);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandrejectIdeal'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = brfilter('ideal', PQ(1), PQ(2), radius, 80);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandpassIdeal'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = bpfilter('ideal', PQ(1), PQ(2), radius, 80);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandpassBW'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = bpfilter('btw', PQ(1), PQ(2), radius, 80,Order);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandrejectBW'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = brfilter('btw', PQ(1), PQ(2), radius, 80,Order);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandpassGaussian'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = bpfilter('gaussian', PQ(1), PQ(2), radius, 80);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
case 'bandrejectGaussian'
axes (handles.FiltAx);
PQ = paddedsize(size(im));
F = fft2(im, PQ(1), PQ(2));
F = fftshift(F);
H = brfilter('gaussian', PQ(1), PQ(2), radius, 80);
G = H.*F;
G = ifftshift(G);
g = real(ifft2(G));
g = g(1:size(im,1), 1:size(im,2));
output = uint8(g);
imshow(output);
imwrite(output,'imagename.jpg');
otherwise
end
handles = WinSize_Callback(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes on button press in export.
function export_Callback(hObject, eventdata, handles)
global output
imwrite(output,'Export\output.png','png','BitDepth', 16);
% --- Executes on slider movement.
function WinSize_Callback(hObject, eventdata, handles)
winSize = get(handles.WinSize,'Value');;
% hObject handle to WinSize (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
% --- Executes during object creation, after setting all properties.
function WinSize_CreateFcn(hObject, eventdata, handles)
% hObject handle to WinSize (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
% --- Executes on slider movement.
function radius_Callback(hObject, eventdata, handles)
% hObject handle to radius (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
axes (handles.FiltAx);
radius = get(handles.radius,'Value');
% --- Executes during object creation, after setting all properties.
function radius_CreateFcn(hObject, eventdata, handles)
% hObject handle to radius (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
% --- Executes on slider movement.
function butterworthOrder_Callback(hObject, eventdata, handles)
% hObject handle to butterworthOrder (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
Order = get(handles.butterworthOrder,'Value');
% --- Executes during object creation, after setting all properties.
function butterworthOrder_CreateFcn(hObject, eventdata, handles)
% hObject handle to butterworthOrder (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

Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!