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')
回答(2 个)
Image Analyst
2020-5-9
Try input:
usersNumber = input('Enter a number : ');
Image Analyst
2020-5-9
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 个评论
himanshu Bedi
2020-5-9
Samreen Shaikh
2022-3-22
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
2022-3-22
@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.
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!