I am working with a lot of images and my workflow has been designed to load up single images, manipulate the image, and write the image back out to a .jpg file. Unfortunatly I recently realised that .jpg is not a loss-less format and I am currently trying to write my image files to .mat variables.
The image write command was useful since I could append text to the file names. Example: load image1.jpg, cropp image1, save as croppedimage1.jpg.
I would like to restore this functionality to my code usings variable names. It may look something like this....
A = [ 1 2 3 4 5 6 7 8 9 10];
for i = 1:10
B = A(i);
C = B*2;
save (i)C % where the variable name would be 1C.mat, 2C.mat etc.
end
I am not sure if this even the right approach.
Thanks for any suggestions.

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 28 日

0 投票

FileName=num2str(i,'C%d.mat')

3 件のコメント

Aaron
Aaron 2011 年 10 月 28 日
I am still missing some functionality. Maybe I am not using the save command correctly. Here is what I did
i = 1;
C = 2;
FileName = num2str(i,'C%d.mat) % This produces FileName = C1.mat
then I save
Save C FileName
This produces the variable filename.mat instead of C1.mat. I was hoping to produce C1.mat, C2.mat, C3.mat etc in my directory.
Any other suggestions would be greatly appreciated.
Thanks!
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 28 日
use the function format, save(FileName)
Aaron
Aaron 2011 年 10 月 28 日
Fangjun,Thanks! Works like a Champ.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 10 月 28 日

0 投票

.jpg is a lossless format if you specify 'Mode', 'lossless' when you do the imwrite(). However, the JPEG lossless format is not as efficient as some of the other lossless formats around.

2 件のコメント

Aaron
Aaron 2011 年 10 月 28 日
Thanks! I went back and looked at the imwrite Help and sure enough there is the lossless command.
I am working on my thesis but I am not much of a programmer.I am just a dirt and rock engineer with an image problem.
Would using the .mat files be more effecient than the .jpg? What other formats would you recomend.
Thanks,
Aaron
Image Analyst
Image Analyst 2011 年 10 月 28 日
Possibly but no other program, such as Photoshop, or even the operating system to produce thumbnail images, will be able to read them. I'd save them as PNG if I were you - that seems to be becoming the most widespread format for lossless images. It's what I use. You might have to cast the arrays to uint8 of or uint16 if you use don't use a .mat format though.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by