imread not working for gif problem

4 ビュー (過去 30 日間)
Yu Li
Yu Li 2019 年 9 月 15 日
コメント済み: Yu Li 2019 年 9 月 16 日
Hi:
I have a gif and I want to read into Matlab, but it does not work, is there any mistake with my operation?
the code is:
imread('giphy.gif', 'frames',100);
imread('giphy.gif', 'frames','all')
the reported error is: Unable to perform assignment because the left and right sides have a different number of elements.
Thanks!
Yu

採用された回答

Rik
Rik 2019 年 9 月 15 日
It took some digging with the debugger, but with enough breakpoints I was able to track down the cause. Your calls are failing because the imgifinfo function fails (it is called by readgif>read_multiframe_gif which is called by imread>call_format_specific_reader). It doesn't return an error, but it doesn't determine a backgroundcolor for the image.
The image has transparent pixels and no background. This is normally not an issue, but the disposalMethod is set to RestoreBG. This is the root cause of your issue. A less strict reader might inject a default background (MSpaint picks black), but the reading function in Matlab doesn't test for this case. I don't know enough of the format specification to know if Matlab is too strict, or that your gif file is simply incorrect.
%these lines fail
%transparent_pixels=background pixels surrounding the arrow
%background_color=[];
%current_frame=the image with the transparent pixels set to 0
% Replace the transparent pixels with the background color
if ~isempty(transparent_pixels)
current_frame(transparent_pixels) = background_color;
end
  1 件のコメント
Yu Li
Yu Li 2019 年 9 月 16 日
Hi:
thanks for your effort. I have contacted Mathworks support to take a deep look.
thank you very much again!
Bests,
Yu

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by