save pig image

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

답변 (3개)

Thomas
Thomas 2012년 3월 30일

0 개 추천

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

Pinco
Pinco 2012년 3월 30일
thanks for you answer!
see comment below
Thomas
Thomas 2012년 3월 30일
to open this image on my MAC I import LS01AL.pgm in MATLAB and use
imshow(LS01AL)

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

Sean de Wolski
Sean de Wolski 2012년 3월 30일

0 개 추천

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

Pinco
Pinco 2012년 3월 30일
i'm sorry for the title!!!
your command run, but if I open the image with textedit (I use Matlab on Mac) i see this:
P5 10 10 255
\cCJ3:(bPI79@)QX68?F/UW<>EGV] =DK4"LSZ*1!ARY[0 'BO
_a&-H
^`N#%,.5 dMT$+2;
Matlab reads this correctly... is it normal?
The same problem with solution by Thomas Anthony.
Sean de Wolski
Sean de Wolski 2012년 3월 30일
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 2012년 3월 30일
With other program, such as Paint Shop Pro, i can see images correctly, but for my purpose i need a file with correct number.

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

Pinco
Pinco 2012년 3월 30일

0 개 추천

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

Image Analyst
Image Analyst 2012년 3월 30일
I don't know. I don't use that format. I think you need to make sure that pgm accepts floating point images. Most formats don't, but like I said, I don't know about pgm. Why not save as a .mat file instead if you need to save a floating point image? Or else convert it to the range 0-255 and save it as a PNG image?
Sean de Wolski
Sean de Wolski 2012년 3월 30일
It only likes integers.
Pinco
Pinco 2012년 3월 30일
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.

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

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

태그

질문:

2012년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by