why append does not working

I'm trying to save multiple images in file
but it save one image
img1 = imread("try1.pgm");
img2 = imread( "try2.pgm");
folder = "/Users/roaaalnader/Documents/MATLAB/TryImg.tif" % file.tif path
folder=fullfile(folder,'img.tif') % to solve you don't have permission error
imwrite(img1,folder);
imwrite(img2,folder,'WriteMode','append' ); % here append doesn't work
%% see the attached picture the file has just the frist image

9 comentarios

Mathieu NOE
Mathieu NOE el 2 de Sept. de 2022
hello
it works ony for multipage TIFF format (as confirmed by the documentation) :
Write Multiple Images to TIFF File
Write multiple images to a single multipage TIFF file.
Create two sets of random image data, im1 and im2.
im1 = rand(50,40,3);
im2 = rand(50,50,3);
Write the first image to a new TIFF file. Then, append the second image to the same file.
imwrite(im1,'myMultipageFile.tif')
imwrite(im2,'myMultipageFile.tif','WriteMode','append')
Rore
Rore el 2 de Sept. de 2022
Thank you I used tif and there is no error now
but it didn't append
now just frist image in file
dpb
dpb el 2 de Sept. de 2022
Don't just say something didn't work, show us the exact code used and the results...
Rore
Rore el 2 de Sept. de 2022
ok i edited the qustion with code
dpb
dpb el 2 de Sept. de 2022
OK, I don't see any overlooked typos like bad capitalization or such that could been a problem...thanks. Always gotta' check all the details before jumping to any conclusions.
So, now, how did you create the image to prove is only one there?
What does
...
imwrite(img1,folder);
!dir '/Users/roaaalnader/Documents/MATLAB/TryImg.tif/img.tif'
imwrite(img2,folder,'WriteMode','append' ); % here append doesn't work
!dir '/Users/roaaalnader/Documents/MATLAB/TryImg.tif/img.tif'
show for the file size?
Seems to work ok here w/ R2020b; what release are you using?
Are you sure that you want
/Users/roaaalnader/Documents/MATLAB/TryImg.tif/img.tif
as your final image name? With the folder having a .tif extension as well as the file having a .tif extension ?
Rore
Rore el 3 de Sept. de 2022
@dpb I checked the file and there is only one image
I'm using R2022a
Rore
Rore el 3 de Sept. de 2022
I want all the image in the TryImg.tif with .tif extension
dpb
dpb el 3 de Sept. de 2022
@Walter Roberson may be on to something with the file naming -- I didn't test that although I did notice it.
...
folder = "/Users/roaaalnader/Documents/MATLAB/TryImg"; % file .tif path
folder=fullfile(folder,'img.tif');
imwrite(img1,folder);
imwrite(img2,folder,'WriteMode','append' ); % here append doesn't work
Then your final file will be in file
/Users/roaaalnader/Documents/MATLAB/TryImg/img.tif
removing the extra .tif on the folder name.
Again, you didn't actually show us the results -- just telling us something isn't enough to be able to prove what did/did not happen.
Show the results between the imwrite calls asked for before so we can see actual results obtained -- we can't see your terminal from here, sorry.

Iniciar sesión para comentar.

Respuestas (2)

Rore
Rore el 3 de Sept. de 2022
Editada: Rore el 3 de Sept. de 2022
Thank you so much for eveyone helped me .
I fixed the problem (append not working) by using sprintf('%d.tif', k); inside loop
to have different name for evey pictre like 1.tif , 2.tif , ...
THE CODE :
for k = 1:10
% read the images from one file
jpgFilename = sprintf('%d.pgm', k);
fullFileName = fullfile("filename", jpgFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName );
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
% then ,I did some process in the image
% after process , save the image
% find the file path to save the image inside it
folderCover="/Users/myName/Documents/MATLAB/Cover.tif"
% make name for every image -> 1.tif , 2.tif , 3.tif , ...
jpgFilename = sprintf('%d.tif', k);
fullFileNameCover = fullfile(folderCover, jpgFilename);
if k ==1 % first time to write
imwrite(imageData,fullFileNameCover );
else
imwrite(imageData,fullFileNameCover,'WriteMode','append')
end
end
Rore
Rore el 3 de Sept. de 2022

0 votos

'WriteMode' is not a recognized parameter is fixed
by using .tif extension to all images and file as

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Sept. de 2022

Editada:

el 3 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by