"Could not open file." using imwrite for png file.

조회 수: 24 (최근 30일)
Niranjan Satam
Niranjan Satam 2013년 3월 22일
댓글: Image Analyst 2020년 7월 9일
global frames;
global fila;
obj=mmreader(fila);
a=read(obj);
frames=get(obj,'numberOfFrames');
for k = 1 : 50
v1(k).cdata = a(:,:,:,k);
v1(k).colormap = [];
end
frames = {v1.cdata};
str2='.png';
for i=1:length(frames)
filename1=strcat(num2str(i),str2 );
imwrite(frames{i},filename1);
data1 = imread(filename1);
data2 = imresize(data1,[144 176]);
iFile = filename1;
imwrite(data2,iFile,'png');
end
frames = {v1.cdata};
??? Error using ==> png
Could not open file.
Error in ==> writepng at 429
png('write', data, map, filename, colortype, bitdepth, ...
Error in ==> imwrite at 477
feval(fmt_s.write, data, map,
filename, paramPairs{:});
Error in ==> main>pushbutton2_Callback at 204
imwrite(data2,iFile,'png');
Sometimes the loop completes giving all the frames of the video of required resolution without any error but sometimes it generates a random number of images and then gives this error. For a few videos i tried, the loop pops up this error even before generating any image at all.
This loop works even without mentioning the 'png' parameter in both imwrite but the result is the same error.
Default toolboxes and block sets present.

채택된 답변

Image Analyst
Image Analyst 2013년 3월 22일
What is the current working directory? If it's something under Program Files, and you're using Windows 7, you won't be allowed to do that. Why are you not using fullfile() to create the full file name of your image files?
Why are you calling imwrite() twice: first to write out the full size frame, and then almost instantly after it to write out the resized image to the same filename. Maybe the first call to imwrite is not done yet, but I'm not sure why you're even calling it the first time to begin with. Try getting rid of the first call to imwrite() or adding a pause() of a half second or so.
  댓글 수: 3
roger
roger 2020년 7월 9일
This works for me. The current directory must be the same folder where you want to save the .png images. Thx.
Image Analyst
Image Analyst 2020년 7월 9일
The folder where you save your image does not have to be the current directory.
You can specify a full path and name to save your image anywhere you want.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by