How do you combine multiple sliders into one on Matlab?

18 次查看(过去 30 天)
I have 3 different sliders doing 3 different things and I'm trying to have all the things being done to it in one function at the same time. I've tried many different things and I still don't know how. If anybody could provide some insight that would be greatly appreciated.
% Load the Image
inputImage = imread("funny-animals-190-02.jpg");
% Display original image
imshow(inputImage)
title('Original Image')
conslider = uislider;
conslider.Position = [150 20 300 3];
conslider.Limits = [0 2];
conslider.Value = 1;
conslider.MajorTicks = [0 0.5 1 1.5 2];
conslider.ValueChangedFcn = @updateImage;
function updateImage(conslider,~)
contrastFactor = conslider.Value;
inputImage = imread("funny-animals-190-02.jpg");
hsvImage = rgb2hsv(inputImage);
outputImage = hsv2rgb(hsvImage);
% Do the stuff for contrast here
outputImage = imadjust(outputImage, [], [], contrastFactor);
% Display the updated image
imshow(outputImage);
title(['contrastFactor: ' num2str(contrastFactor)]);
end
% Load the Image
inputImage = imread("funny-animals-190-02.jpg");
% Display original image
imshow(inputImage)
title('Original Image')
% Developing a slider to adjust the saturation
satslider = uislider;
satslider.Position = [150 20 300 3];
satslider.Limits = [0 2];
satslider.Value = 1;
satslider.MajorTicks = [0 0.5 1 1.5 2];
satslider.ValueChangedFcn = @updateImage
function updateImage(satslider,~)
% Read the current saturation value from the slider
saturationFactor = satslider.Value;
% Convert the image to HSV color space
inputImage = imread("funny-animals-190-02.jpg");
hsvImage = rgb2hsv(inputImage);
% Update the saturation (S)
hsvImage(:, :, 2) = hsvImage(:, :, 2) * saturationFactor;
% Convert the modified image back to RGB color space
outputImage = hsv2rgb(hsvImage);
% Do the stuff for contrast here
% Display the updated image
imshow(outputImage);
title(['Saturation Factor: ' num2str(saturationFactor)]);
end
% Load the Image
inputImage = imread("funny-animals-190-02.jpg");
% Display original image
imshow(inputImage)
title('Original Image')
sharpslider = uislider;
sharpslider.Position = [150 20 300 3];
sharpslider.Limits = [0 2];
sharpslider.Value = 1;
sharpslider.MajorTicks = [0 0.5 1 1.5 2];
sharpslider.ValueChangedFcn = @updateImage;
function updateImage(sharpslider,~)
sharpenFactor = sharpslider.Value;
inputImage = imread("funny-animals-190-02.jpg");
hsvImage = rgb2hsv(inputImage);
outputImage = hsv2rgb(hsvImage);
% Do the stuff for contrast here
outputImage = imsharpen(inputImage, 'Amount', sharpenFactor);
% Display the updated image
imshow(outputImage);
title(['sharpenFactor: ' num2str(sharpenFactor)]);
end

回答(2 个)

Samson
Samson 2024-4-12
移动:Matt J 2024-4-12
This sounds like an easy task in the Matlab App Designer.
To go to the app designer find the 'Apps' tab in the top left of the matlab client, and then 'Design app'.
Drag three sliders and an axes from the component browser. Either add a button, right click and add a function callback on button press to update the image, or add callbacks on value change to the sliders depending on desired result.
Good luck!

Umar
Umar 2024-5-5

To combine the functionalities of multiple sliders into one function in Matlab, you can create a single callback function that handles the actions of all three sliders simultaneously. Within this callback function, you can access the values of each slider and perform the desired operations accordingly.

Here is a simplified example to illustrate this concept: function combinedSliderFunction(src, event) valueSlider1 = src.Value; % Get value of slider 1 valueSlider2 = event.Source.Parent.Children(2).Value; % Get value of slider 2 valueSlider3 = event.Source.Parent.Children(3).Value; % Get value of slider 3

    % Perform operations based on the values of the sliders
    % Add your logic here
    disp(['Slider 1 Value: ', num2str(valueSlider1)]);
    disp(['Slider 2 Value: ', num2str(valueSlider2)]);
    disp(['Slider 3 Value: ', num2str(valueSlider3)]);
end

In this function, src represents the handle of the slider that triggered the callback, and event contains information about the event. By accessing the values of all three sliders within this function, you can synchronize their actions effectively. Customize the logic inside the function to suit your specific requirements.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by