필터 지우기
필터 지우기

Conversion of 100 jpg images to PGM

조회 수: 6 (최근 30일)
shawin
shawin 2018년 10월 1일
댓글: Image Analyst 2020년 9월 19일

Kindly how can we convert 100 images which are jpg to PGM format?

the Matlab code for one image conversion is:

I = imread('myImage.jpg');
       imwrite(I,'myImage7.pgm');

then if we have 100 jpg images how we can convert them to pgm format?

채택된 답변

Image Analyst
Image Analyst 2018년 10월 1일
  댓글 수: 7
Guillaume
Guillaume 2018년 10월 3일
Seriously, use a better image viewer, one that includes batch format conversion. A few were already suggested. You would have solved your problem in a matter of minutes.
Image Analyst
Image Analyst 2018년 10월 3일
I don't know what "opensleeit" is.
When you run the program, imshow() shows/displays each image as it's loaded. Are you saying imshow() does not work for you?
Why do you want PGM format images anyway? Isn't that some obsolete format from the 90's? Why not just leave them as they are, or use PNG format, which has become the defacto standard?
Since the images have already been ruined by saving in JPG format, converting to another format won't gain you anything. Plus nearly every program that "sees" PGM images will also see JPG images.

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

추가 답변 (3개)

John D'Errico
John D'Errico 2018년 10월 1일
Use a loop? Surely you can get the directory contents, so the names of all images in a directory, using a tool like dir. Now just loop over the images that dir returns.
  댓글 수: 1
shawin
shawin 2018년 10월 2일
편집: shawin 2018년 10월 2일
myFolder = 'C:\Users\shawin\Desktop\FR_Matlab\FR_Test7\Database_2';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
imageArray2=imwrite(imageArray,'myImg(k).name.pgm');
end
it does not work?

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


Guillaume
Guillaume 2018년 10월 2일
Even simpler, particularly if you don't have the knowledge to write the code is to download any decent image viewer program that will surely include batch image conversion as one of its feature.
My favorite, which is free for personal and academic use is IrfanView. Start the program, press B (for batch conversion), select the images to convert, select PGM in output format, Press Start Batch. Done!
  댓글 수: 2
Image Analyst
Image Analyst 2018년 10월 2일
I like ACDSee, which has a similar feature.
Guillaume
Guillaume 2018년 10월 2일
ACDSee is still around! I remember using that in the 90s. There's also XnView which is also free and probably many more that can do this in a few clicks. And if you prefer command line, there's always ImageMagick, which again, can do the job in just one command.
The point is, you don't always have to use matlab to solve your problems.

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


kalai selvi
kalai selvi 2020년 9월 19일
how to convert the scatter plot fig into pgm
  댓글 수: 1
Image Analyst
Image Analyst 2020년 9월 19일
Try exportgraphics() if using r2020a or later. Otherwise try export_fig.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by