How can I draw a slider for image comparison?

3 vues (au cours des 30 derniers jours)
Muhammad Abir
Muhammad Abir le 10 Avr 2020
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.
clc
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');
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;
end
end

Réponse acceptée

Anirudh Singh
Anirudh Singh le 17 Avr 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( https://www.w3schools.com/howto/howto_js_image_comparison.asp ) 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.
Or
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:

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by