Image displaying using GUI (User based choice)

Hello,
I am trying to create a code which can show or dipslays image, based on users choice so far I have created a code which runs and display image from desktop and shows it. I want to create a code using GUI which shows image from the list in a given folder from computer. I want the code to ask user to press 1 for this image and press 2 for another image or 3 to quit etc. How can I achieve this ?
Thanks
spec = imread('specs.jpg');
scene = imread('Image.jpg');
spec = rgb2gray(spec);
scene = rgb2gray(scene);
figure(1);
imshow(spec);
figure(2);
imshow(scene);
figure(3);
specPoints = detectSURFFeatures(spec);
scenePoints = detectSURFFeatures(scene);
[specFeatures, specPoints] = extractFeatures(spec, specPoints);
[sceneFeatures, scenePoints] = extractFeatures(scene, scenePoints);
matchPairs = matchFeatures(specFeatures, sceneFeatures);
matchedPoints = specPoints(matchPairs(:,1),:);
matchedsPoints = scenePoints(matchPairs(:,2),:);
[tform, inlierSpecPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedPoints, matchedsPoints,...
'affine');
Polygon = [1, 1;...
size(spec, 2), 1;...
size(spec, 2), size(spec, 1);...
1, size(spec, 1);...
1, 1];
newBoxPolygon = transformPointsForward(tform, Polygon);
imshow(scene);
%hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y')

Respuestas (2)

Image Analyst
Image Analyst el 9 de Mayo de 2020
Try this to make a list of all images in the folder on buttons. The user then clicks the button with the image name that he wants to use. Change the "folder" variable to whatever folder contains your images.
%===============================================================================
% Get the name of the demo image the user wants to use.
% Let's let the user select from a list of all the demo images that ship with the Image Processing Toolbox.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
% Demo images have extensions of TIF, PNG, and JPG. Get a list of all of them.
imageFiles = [dir(fullfile(folder,'*.TIF')); dir(fullfile(folder,'*.PNG')); dir(fullfile(folder,'*.jpg'))];
for k = 1 : length(imageFiles)
% fprintf('%d: %s\n', k, files(k).name);
[~, baseFileName, extension] = fileparts(imageFiles(k).name);
ca{k} = [baseFileName, extension];
end
% Sort the base file names alphabetically.
[ca, sortOrder] = sort(ca);
imageFiles = imageFiles(sortOrder);
button = menu('Use which demo image?', ca); % Display all image file names in a popup menu.
% Get the base filename.
baseFileName = imageFiles(button).name; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);

3 comentarios

himanshu Bedi
himanshu Bedi el 9 de Mayo de 2020
I will try this thanks.
Samreen Shaikh
Samreen Shaikh el 22 de Mzo. de 2022
Hey I wanted to allow my user to select an image from their end and get the desired output...how can I do that in MATLAB
Image Analyst
Image Analyst el 22 de Mzo. de 2022
@Samreen Shaikh the best way is to load a listbox with all the images in the folder of interest. I suggest you use MAGIC:
When you click on a filename in the listbox, it displays it.
Adapt it by changing the AnalyzeSingleImage() function to do the operations you want.
If it's not working, then post your changes to it.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Mayo de 2020

Comentada:

el 22 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by