MATLAB Answers

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

42 ビュー (過去 30 日間)
Christian Rouhana
Christian Rouhana 2021 年 7 月 22 日
回答済み: Christian Rouhana 2021 年 7 月 26 日
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);
end
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.
  11 件のコメント
Jan
Jan 2021 年 7 月 24 日
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
'01001010'
'11111000'
'11111100'
'11000010' % Uploaded
'10011110'
'01001010'
'11000011'
'10111000'
'11000011'
'10111100'
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.

サインインしてコメントする。

採用された回答

Christian Rouhana
Christian Rouhana 2021 年 7 月 26 日
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.

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 7 月 22 日
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 2021 年 7 月 24 日
"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.
  3 件のコメント
Jan
Jan 2021 年 7 月 25 日
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by