how to read a grey scale image in call back function and display it as matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
% Callback function for the "Load Image" button
function loadImageCallback(hObject, eventdata, handles)
% Open a file dialog to select an image
[fileName, filePath] = uigetfile({'*.jpg;*.png;*.bmp;*.tif', 'All Image Files'; '*.*', 'All Files'}, 'Select an Image');
% Check if a file was selected
if isequal(fileName, 0)
return; % User canceled the operation
end
% Read the selected image
img = imread(fullfile(filePath, fileName));
% Check if the image was read successfully
if isempty(img)
errordlg('Failed to read the image', 'Error');
return;
end
% Store the image data in the handles structure
handles.img = img;
% Update the handles structure
guidata(hObject, handles);
% Optionally, display a message to indicate successful loading
msgbox('Image loaded successfully', 'Success');
end
0 件のコメント
回答 (1 件)
Adam Danz
2024 年 5 月 29 日
編集済み: Adam Danz
2024 年 5 月 30 日
2 件のコメント
DGM
2024 年 5 月 30 日
編集済み: DGM
2024 年 5 月 30 日
Just to get ahead of any complications, I'm of the opinion that any users of versions R2020b or newer should not be using rgb2gray() unless they're catering to older versions with the appropriate care. The only difference between rgb2gray() and im2gray() is that im2gray() will pass single-channel inputs as if gray, whereas rgb2gray() will throw an error.
Otherwise, all blind usage of rgb2gray() necessarily must come wrapped in a check for the size of dim3 to prevent errors. I don't know why this basic improvement was implemented as a mostly redundant function instead of improving the existing rgb2gray() (maybe the implications of the function name itself), but it is what it is.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!