I'd like to draw a circle for a slider like this (https://www.w3schools.com/howto/howto_js_image_comparison.asp). 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.
clcclear 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');imshow(im_left);hold(ax);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; endend
Best Answer