MATLAB Answers

Problems with 'uigetfile' and 'imread' in simple MATLAB Web App

45 views (last 30 days)
Hi All,
I am trying to convert a MATLAB App Designer App to a Web App. After viewing this page on the limitations of a MATLAB Web App, I do not see any incompatibilites. However, I am having a problem with loading images with 'uigetfile' and being able to read them with 'imread'. To investigate this, I created a really simple test app. There is a push button and a UIAxes, and the push button allows the user to upload an image that will be displayed in the UI Axes. Here is the code for said push button.
function imageButtonPushed(app, event)
[files, path] = uigetfile("*.*", 'Multiselect', 'on');
imshow(imread(fullfile(path, files)), 'parent', app.UIAxes);
But when I upload a test .tif image, I consistently get this error.
When I navigate to the temporary folder where 'uigetfile' stores the image, I can not open them in any image viewing app. They seem to get corrupted in the process. I can not share the image because it is from a lab and I do not want to get in trouble, but I can guarantee that the image is not corrupted and the process works in an offline setting with the exact same image file. Am I missing something very obvious?
Thank you in advance to anyone who lends their help.
Jan on 24 Jul 2021
There are more differences: The "resultpng.png" starts with 0xc2 and some other 0xc2 are instered also. But e.g.
' 9E 4A F8 FC' becomes
'C2 9E 4A C3 B8 C3 BC'
% Or as bits:
'10011110' % Original
'11000010' % Uploaded
The upload has inserted 25 bytes and modified some existing bytes. It does not look like a confused UTF8 to UTF16 conversion.
Please contact MathWorks to ask for help. I assume that they can debug the problem.

Sign in to comment.

Accepted Answer

Christian Rouhana
Christian Rouhana on 26 Jul 2021
Hi all,
Thank you for your help. I contacted MATLAB support and this seems to be a bug found in MATLAB R2021a. I installed MATLAB R2020b and do not have this problem anymore.

More Answers (2)

Walter Roberson
Walter Roberson on 22 Jul 2021
My interpretation would be that libTiff on the server is not the same as libTiff on the online version.
In particular if you are using Linux on the server, then you probably need to install an older version of libTiff for MATLAB to use.

Image Analyst
Image Analyst on 24 Jul 2021
"If my goal is to have the user be able to upload one or more image(s) for analysis, is there a correct way to do this?" <== Waht I would do is to have your app load a listbox full of images they can select from so they can just easily click one or more to analyze, and then click the Analyze or Go button to do the batch processing. I'd also have a button that calls uigetdir() so the user can specify what folder's files get loaded into the listbox.
Jan on 25 Jul 2021
You can use uigetfile() in a Web-App to choose files. This uploads the selected files to a local folder, which can be accessed by the web server. The idea is give the web server access only to the selected files. Everything else would be a security problem.
Now the problem of the OP is, that the local copy of the files is damaged by the uigetfile() processing: some bytes are inserted, some bits are modified.
There are more users withthis problem.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by