How can I draw a slider for image comparison?

10 views (last 30 days)
I'd like to draw a circle for a slider like this ( I can slide and compare the images, however, I can't make a circle like the one they made it so I can hold the mouse inside that circle and adjust the slider.
Here is the code for image comparison.
clear all
close all
im_left = im2double(imread('pears.png')); % opening two example images
im_right = im2double(imread('peacock.jpg'));
im_right = imresize(im_right, size(im_left, [1 2])); % making the dimensions equal
f = figure();
ax = axes('Units', 'pixels');
im_handle = imshow(im_right);
im_handle.AlphaData = zeros(size(im_left, [1 2]));
axes_pos = cumsum(ax.Position([1 3]));
f.WindowButtonMotionFcn = {@cb, size(im_left,2), im_handle, axes_pos};
function cb(obj, ~, im_width, im_handle, axes_pos)
x_pos = obj.CurrentPoint(1);
if x_pos > axes_pos(1) && x_pos < axes_pos(2)
left_cols = floor(floor(x_pos - axes_pos(1))/diff(axes_pos) * im_width);
im_handle.AlphaData(:, 1:left_cols) = 0;
im_handle.AlphaData(:, left_cols+1:end) = 1;

Accepted Answer

Anirudh Singh
Anirudh Singh on 17 Apr 2020
I understand you want to make slider on two images for comaprision. But nowhere you used Css property which is present in the link( ) you provided. You can do this by using importing mlreportgen.dom.* and then defining yu css properties.
I am attaching the link for how you can define your css properties.
The latest Matlab GUI (created using the App Designer tool or the uifigure function) is based on HTML, JavaScript and CSS - not on Java Swing. You can check here:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by