How do I toggle images in the GUI

5 views (last 30 days)
Jeffrey
Jeffrey on 22 Aug 2013
I am a current student and am relatively new to MATLAB. I am currently using an accelerometer as controller.
What I am trying to do is to replace an image when the accelerometer reads a value greater then a set threshold and return to the original image when it is not. This is what I currently have in a while loop
if handles.thresholdValue <= handles.gxFiltdata;
axes(handles.axes9);
imshow('RED.JPEG');
else
axes(handles.axes9);
imshow('BLACK.JPEG');
end
As of right now the image starts off black and turns red and stays red regardless of whether or not the accelerometer reads above or below the threshold set

Answers (1)

Image Analyst
Image Analyst on 22 Aug 2013
Put this before your if statement
fprintf('thresh=%f, gxFilt=%f\n', handles.thresholdValue, handles.gxFiltdata)
What does it show in the command window? Next, go here and watch it: http://blogs.mathworks.com/videos/category/gui-or-guide/
  4 Comments
Jeffrey
Jeffrey on 26 Aug 2013
Edited: Jeffrey on 26 Aug 2013
Even when I change the if statement to
'if handles.gxdata <= .5;'
The image stays put at red. Is here something wrong with what is inside the loop itself?
Image Analyst
Image Analyst on 26 Aug 2013
Is this an image and you're wanting to change the image to pure red if the image value is less than the threshold and to black if it's above the threshold? If so, you can just do (untested):
binaryImage = (handles.gxFiltdata >= handles.thresholdValue)
imshow(binaryImage);
myColormap = [1,0,0;0,0,0];
colormap(myColormap);
colorbar;

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!