When I read a pgm file on matlab and read it for some reason it changes the elements, how can i prevent that from happening? I can't attach the image but can someone help me in making sure the elements dont change when reading a pgm file, thank you

3 vues (au cours des 30 derniers jours)
myFolder = ''; % this has the path file for where the pgm files are stored
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.pgm');
pgmFiles = dir(filePattern);
n = 13;
I=zeros(1000,1000,1000);
for k = 1:length(pgmFiles)
baseFileName = pgmFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
A{k} = imread(fullFileName);
end
  2 commentaires
T Vinai Datta Reddy
T Vinai Datta Reddy le 18 Avr 2019
I'm facing the same issue too.
For instance, when I try to display the first 15 values of the image in C, I get -
2 2 2 2 2 2 2 2 2 3 3 2 3 3 2
And in Matlab,
img(1:15)
the values are -
265 265 265 265 265 265 265 265 265 397 397 265 397 397 265
Observe that the pattern is same.
Anyway, I'm unable to upload the image file here since .pgm is an unsopperted format, so here you go -
Image Analyst
Image Analyst le 19 Avr 2019
I downloaded it and brought it into Photoshop and it looks like garbage.
flower_grad.png
It actually looks better in MATLAB!
0001 Screenshot.png
The image is a 16 bit (2 byte) image. The values MATLAB gives are 100% reasonable and believable. I suspect in C you are assuming it's a uint8 image and reading it a byte at a time, thus giving the incorrect (low) values, instead of reading two bytes (a pair of bytes) into a uint16 variable.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 30 Jan 2017
I don't believe it is changing the values. For you to prove it is, you'll have to upload a file that we can read in with MATLAB, and some other program, such as Photoshop, where we can see that the color or graylevel at a certain location is not the same in the two different programs.
  4 commentaires
Image Analyst
Image Analyst le 1 Fév 2017
Syed, we can't really do anything more unless you attach the image and say what alternate method (other than MATLAB) you're using to check the values. Just attach an image with non-proprietary content if you can.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Big Data Processing dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by