Re: [R] PPM to BMP converter

2012-05-09 Thread Jan van der Laan


I don't know if any R-packages exist that can do this, but you could  
install imagemagick (http://www.imagemagick.org), which provides  
command line tools for image manipulation and conversion, and call  
these from R using system. Something like:


system(convert yourimage.ppm yourimage.bmp)

HTH,

Jan



ZHANG Yingqi zhangyin...@ivpp.ac.cn schreef:


Dear all,
Several days ago, I posted How to write a bmp file pixel by  
pixel. Instead of bmp, I succeeded in writing a PPM file by using  
the pixmap package. Thanks for the hint generously provided by Uwe  
Ligges.
Now I have a new question. How to convert a PPM file to BMP  
file in R? I know I can do this in photoshop or by some other  
softwares, but I think if I Can do this in R, that would be great!  
Would anyone please give me any hints? just hints, I will dig it  
out! Thanks a lot!



Yingqi


Yingqi ZHANG

Beijing P.O. Box 643, China 100044
Institute of Vertebrate Paleontology and Paleoanthropology (IVPP)
Chinese Academy of Sciences
Tel: +86-10-88369378 Fax: +86-10-68337001
Email: arvico...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PPM to BMP converter

2012-05-09 Thread Michael Sumner
You could write it to BMP with rgdal, i.e. with dummy world coordinates:

x1 - list(x = 1:5, y = 1:4, z = matrix(1:20, 5, 4))

require(sp)
x2 - image2Grid(x1)

require(rgdal)
writeGDAL(x2, file.bmp, driver = BMP, type = Byte, mvFlag = 255)

(I am not familiar with the details of what BMP can support, so I just
limit to Byte and stay safe. )

To show the round trip, convert back to image xyz list:

as.image.SpatialGridDataFrame(readGDAL(file.bmp))$z
file.bmp has GDAL driver BMP
and has 4 rows and 5 columns
 [,1] [,2] [,3] [,4]
[1,]16   11   16
[2,]27   12   17
[3,]38   13   18
[4,]49   14   19
[5,]5   10   15   20

I was a bit surprised to find that there seem to be no coercion
functions to convert to/from pixmap within the family of packages that
include maptools, sp, spatstat  and raster , they would be useful. I
would say that raster would be the best bet in the first instance
since it can store the different colour models directly. There is also
new rasterImage support in the graphics package that is worth
mentioning. All of these packages have different data structures, but
there is a growing set of coercion functions and it's not too hard
once you understand them to do it yourself.

Cheers, Mike.




On Wed, May 9, 2012 at 8:31 AM, ZHANG Yingqi zhangyin...@ivpp.ac.cn wrote:
 Dear all,
        Several days ago, I posted How to write a bmp file pixel by pixel. 
 Instead of bmp, I succeeded in writing a PPM file by using the pixmap 
 package. Thanks for the hint generously provided by Uwe Ligges.
        Now I have a new question. How to convert a PPM file to BMP file in R? 
 I know I can do this in photoshop or by some other softwares, but I think if 
 I Can do this in R, that would be great! Would anyone please give me any 
 hints? just hints, I will dig it out! Thanks a lot!


 Yingqi
 

 Yingqi ZHANG

 Beijing P.O. Box 643, China 100044
 Institute of Vertebrate Paleontology and Paleoanthropology (IVPP)
 Chinese Academy of Sciences
 Tel: +86-10-88369378     Fax: +86-10-68337001
 Email: arvico...@gmail.com

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsum...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] PPM to BMP converter

2012-05-08 Thread ZHANG Yingqi
Dear all,
Several days ago, I posted How to write a bmp file pixel by pixel. 
Instead of bmp, I succeeded in writing a PPM file by using the pixmap package. 
Thanks for the hint generously provided by Uwe Ligges. 
Now I have a new question. How to convert a PPM file to BMP file in R? 
I know I can do this in photoshop or by some other softwares, but I think if I 
Can do this in R, that would be great! Would anyone please give me any hints? 
just hints, I will dig it out! Thanks a lot!


Yingqi


Yingqi ZHANG

Beijing P.O. Box 643, China 100044
Institute of Vertebrate Paleontology and Paleoanthropology (IVPP)
Chinese Academy of Sciences
Tel: +86-10-88369378 Fax: +86-10-68337001
Email: arvico...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.