save pig image

1 visualización (últimos 30 días)
Pinco
Pinco el 30 de Mzo. de 2012
this is my code:
t = 'P10307';
u = 65;
n = 1;
for i = 1:12
name = [t num2str(u) '.JPG'];
A = imread(name);
A = rgb2hsv(A);
V = A(:,:,3);
filename = ['LS0' num2str(n) 'AL'];
imwrite(V,filename','pgm')
u = u+1;
n = n+1;
end
I have to obtain just 'V' component and I have to save it as 'pmg' , but an error occurs when I try to do this. What's the problem?
Thanks a lot for your answer. G. Rossi

Respuestas (3)

Thomas
Thomas el 30 de Mzo. de 2012
try
filename = ['LS0' num2str(n) 'AL.pgm'];
imwrite(V,filename)
should work,
I think yours did not work because when you specify format pgm , the second string in imwrite is the colormap..
  2 comentarios
Pinco
Pinco el 30 de Mzo. de 2012
thanks for you answer!
see comment below
Thomas
Thomas el 30 de Mzo. de 2012
to open this image on my MAC I import LS01AL.pgm in MATLAB and use
imshow(LS01AL)

Iniciar sesión para comentar.


Sean de Wolski
Sean de Wolski el 30 de Mzo. de 2012
Pigs are known to be stubborn occasionally, fortunately you're not trying to save a mule image.
Does this work?
imwrite(uint8(magic(10)),'pig.pgm','pgm')
imread('pig.pgm')
?
  3 comentarios
Sean de Wolski
Sean de Wolski el 30 de Mzo. de 2012
You need to make sure you're using integer classes, hence why I wrapped uint8() around the above. It's not surprising to me that an image file appears as gibrish in a text editor. Try opening any other image in a text edit and you'll see the same thing. MATLAB knows the file format so it can read the binary correctly. Does it look good in another image viewer?
Pinco
Pinco el 30 de Mzo. de 2012
With other program, such as Paint Shop Pro, i can see images correctly, but for my purpose i need a file with correct number.

Iniciar sesión para comentar.


Pinco
Pinco el 30 de Mzo. de 2012
Now my code is:
t = 'P10307';
u = 65;
n = 1;
for i = 1:12
name = [t num2str(u) '.JPG'];
A = imread(name);
A = rgb2hsv(A);
V = A(:,:,3);
filename = ['LS0' num2str(n) 'AL.pgm'];
imwrite(V,filename,'pgm')
u = u+1;
n = n+1;
end
  3 comentarios
Sean de Wolski
Sean de Wolski el 30 de Mzo. de 2012
It only likes integers.
Pinco
Pinco el 30 de Mzo. de 2012
If I change "V = A(:,:,3);" with "V = A(:,:,3)*255;" it's the same.
I need a pgm file because my teacher, after, has to work with this file in a fortran program.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by