Retrieve the pixel values of an image with Haskell - haskell

Is there a way or a library available that can load an image (jpeg, png, etc) and assign the pixel values of that image into a list or matrix? I'd like to do some experiments with image and pattern recognition.
A little nudge in the right direction would be appreciated.

You can use JuicyPixels, a native Haskell library for image loading. This is rather easy to convert to REPA as well (manually or with JuicyPixesl-repa).

I've used the repa-devil package for this in the past. It lets you work with a bunch of formats using Developer's Image Library (DevIL). You can read and write all the formats you are likely to care about.
The actual image data is given as a Repa array. This is a great library for array operations and makes it very easy to write parallel code.

Try the repa library
.Also there is a small tutorial here

Here is a new Haskell Image Processing library, which uses JuicyPixels for encoding, provides interface for you to read and write all of the supported formats in a very easy manner and manipulate them in any way you can imagine. Just as a simple example on how easy it is:
>>> img <- readImageRGB "image.jpg"
>>> writeImage "image90.png" $ rotate90 img
Above will read a JPG image in RGB color space, rotate it 90 degrees clockwise and save it as a PNG image.
Oh yeah, it also can use Repa, so you will get parallel processing for free as well.

GTK supports loading and saving JPEG and PNG. [AFAIK, no other formats though.] There is a Haskell binding named Gtk2hs. It supports vector graphics very well, but bitmap graphics, while supported, isn't especially easy to figure out. So I wrote AC-EasyRaster-GTK, which wraps GTK in a more friendly interface. (It still needs Gtk2hs though.) The only real down-side is that Gtk2h is a bit fiddly to set up on Windows. (And it's arguably overkill to install an entire GUI toolkit just to load and save image files.)
I gather the "GD" library supports writing several image formats, and is quite small and simple. I believe Hackage has Haskell bindings for GD as well. I haven't tried this personally.
There is a file format called PPM which is deliberately designed to be ridiculously easy to implement (it's a tiny header and then an array of pixels), and consequently there's at least a dozen packages on Hackage which implement it (including my own AC-PPM). There are also lots of programs out there which can display and/or convert images in this format.

Related

How can I create a 3D model file from geometric shapes?

I am writing a program that will output 3D model files based on simple geometric shapes (e. g. rectangular prisms & cylinders) with known coordinates in 3-dimensional space. As an example, imagine creating a 3D model of stonehenge. this question suggests that OBJ files are the easiest to generate, but I'm struggling to find a good tutorial or easy-to-use library for doing so.
Can anyone either
(1) describe step-by-step how to create a simple file OR
(2) point me to a tutorial that describes how to do so
Notes:
* Using a GUI-based program to draw such files is not an option for me
* I have no prior experience with 3D modeling
* Other formats such as WRL or DAE would work for me as well
EDIT:
I do not need to use textures, just combinations of simple geometric shapes positioned in 3D space.
I strongly recommend to use some ASCII exchange format there are many out there I usually use these:
*.x DirectX object (it is a C++ source code)
this one is easiest to implement !!! But there are not many tools that can handle them. If you do not want to spend too much time coding then this is the right choice. Just copy the templates (at the start) from any *.x file to get started.
here some specs
*.iges common and importable on most CAD/CAM platform (Catia included)
this one is a bit complicated but for export purposes it is not that bad. It supports Volume operation like +,-,&,^ which are VERY HARD to implement properly but you do not have to use them :)
*.dxf AutoCAD exchange format
this one is even more complicated then IGES. I do not recommend to use it
*.ac AC3D
I first saw this one in flight gear.
here some specs
at first look it is quite easy but the sub-object implementation is really tricky. Unless you use it you should be fine.
This approach is easily verifiable in note pad or by loading to some 3D model viewer. Chose one that is most suitable for your needs and code save/load function to your Apps internal model class/struct. This way you will be compatible with other software and eliminate incompatibility problems which are native to creating 'almost known' binary formats like 3ds,...
In your case I would use IGES (Initial Graphics Exchange Specification)
For export you do not need to implement all just few basic shapes so it would not be too difficult. I code importers which are much much more complicated. Mine IGES loader class is about 30KB of C++ source code look here for more info
You did not provide any info about your 3D mesh model structure and capabilities
like what primitives you use, are your object simple or in skeleton hierarchy, are you using textures, and more ... so it is impossible to answer
Anyway export often looks like this:
create header and structure of target file format
if the format has any directory structure fill it and write it (IGES)
for sub-objects do not forget to add transformation matrices ...
write the chunks you need (points list, faces list, normals, ...)
With ASCII formats you can do this inside String variable so you can easily insert into or modify. Do all thing in memory and write the whole thing to file at the end which is fast and also add capability to work with memory instead of files. This is handy if you want to pack many files to single package file like *.pak or send/receive files through IPC or LAN ...
[Edit1] more about IGES
fileformat specs
I learned IGES from this pdf ... Have no clue where from I got it but this was first valid link I found in google today. I am sure there is some non registration link out there too. It is about 13.7 MB and original name IGES5-3_forDownload.pdf.
win32 viewer
this is free IGES viewer. I do not like the interface and handling but it works. It is necessary to have functional viewer for testing yours ...
examples
here are many tutorial files for many entities there are 3 sub-links (igs,peek,gif) where you can see example file in more ways for better understanding.
exporting to IGES
you did not provide any info about your 3D mesh internal structure so I can not help with export. There are many ways to export the same way so pick one that is closest to your App 3D mesh representation. For example you can use:
point cloud
rotation surfaces
rectangle (QUAD) surfaces
border lines representation (non solid)
trim surface and many more ...

what format of pic can generate mimap in opengl-es

as the title, I used to use .dds, it did work,now I use type of .png, can it generate mipmap? Here functions what I am using: glTexImage2D(…).Or maybe gluBuild2DMipmaps(…) a better choice?
DDS are an image format that contains precalculated mipmaps. As far as quality goes, precalculated mipmaps offer the best quality, since they can be downsampled offline with advanced filter kernels like Lancozs, without having to care about runtime efficiency.
PNG does not contain additional mipmap levels so you have to compute the mipmaps at runtime. You should however not use gluBuild2DMipmaps for this. For one this function is known to exhibit buggy behavior in certain conditions and furthermore it will unconditionally resample all images to power-of-2 dimensions, although since OpenGL-2 non power-of-2 dimensions are perfectly fine for texture images.
Instead you should load the base level image with glTexImage2D(…) and use glGenerateMipmap(…) (available since OpenGL-3) to build the mipmap image pyramid from there. If you don't use OpenGL-3, you can use the SGIS_generate_mipmap extension, if available.
However be advised that online mipmap generation may yield not as good results as offline generation.
Another possible approach would be the use of JPEG2000 images; the nature of JPEG2000 image encoding results in an image pyramid being readily available. OTOH JPEG2000 is very costly to encode and decode.

Producing Vector Graphics Movies with something like Nodebox or Processing

I like the idea of Nodebox and Processing, and would like to generate movies to visualize some data/algorithms. However, Nodebox exports extremely bloated Quicktime files with frame by frame images, and Processing only exports Java applications. I want to be able to export movies that don't take a Gigabyte a minute of disk space. Perhaps something like SVG animations or Actionscript which stores the vector graphics definition of the animation rather than frame images would be better. Is there a framework that is as easy to program as Nodebox and Processing and can export "lean" movies?
Have you tried the MovieMaker library that ships with Processing ?
Also, it should be fairly simple to save multiple frames using saveFrame().
This is option have a couple of advantages:
If your sketch crashes at some point, you still have all the frames up to that point (unlike writing a .mov file)
It's fairly simple to put the frames back into a video file, but you also have control over playback speed and can easily do a bit of editing if needed.
You can try to a sequence of PDF file using createGraphics() to get vector output, but I'm not sure how stable/feasible this option is.
They are changing the way this works moving towards 2.0 too, as they are moving to GSVideo over Quicktime...
Daniel Shiffman posted about it recently on his blog, but it's the only place I've heard about any changes to post-2.0 tactics (though he IS part of the inner circle, I know)
You can find that post at
http://www.shiffman.net/2011/12/28/night-8-rendering-out-as-image-sequence/
Also, if you are on OSX, you can try Syphon ? See info here
https://forum.processing.org/topic/syphon-integration-with-processing

Save image with ocaml graphics

i want to save the picture generated by ocaml graphics in a file (png or jpeg).
Thank you.
I'm going to assume that you are talking about the Graphics module in ocaml.
You should notice that the Graphics module isn't for creating and processing images. You can of course call Graphics.dump_image if you've already gone ahead and wrote something that produces the Graphics.image type. This will produce a color array array, where color is a packed integer in the format, 0xRRGGBB.
After some other conversion functions you should call upon camlimages to produce your image, and there is a code sample from another question.

Which 3D Model format should I be using?

Im writing a game engine and I'm wondering what 3D model format should I use/load/export? Obj seems universal and easy but it also appears to be unreliable in that most models out there contain errors and it doesn't store anywhere near as much as other formats.
There appear to be formats specifically for games such as MD2/3/5 but Im not sure, I use wings3d if I model, and I don't know what other details beyond purely loading what I need and support from the format Id have to implement, such as would I need to implement IK? and can I use scripted per piece animation rather than Inverse kinematics and bone rigging?
Collada is an open XML based format for 3d models owned by the Khronos group(OpenGL standards body)
From the Collada.org FAQ:
The COLLADA 1.4.x feature set includes:
Mesh geometry
Transform hierarchy (rotation, translation, shear, scale, matrix)
Effects
Shaders (Cg, GLSL, GLES)
Materials
Textures
Lights
Cameras
Skinning
Animation
Physics (rigid bodies, constraints, rag dolls, collision, volumes)
Instantiation
Techniques
Multirepresentations
Assets
User data
Before worrying about what 3D formats you want to support, I think you should really focus on what features you are planning to implement in your engine. Write those down as requirements, and pick the format that supports the most features from the list... as you'll want to showcase your engine (I am assuming you are planning for your engine to be publicly available). You might even want to roll your own format, if your engine has specific features (which is always a good thing to have for a game engine).
After that, support as many of the popular formats as you can (.X, .3DS, .OBJ, .B3D)... the more accessible your engine is, the more people will want to work with it!
Collada is a nice and generic format, but like Nils mentions, it is not an ideal format for final deployment.
I use my own binary format. I've tried to use existing formats but always run into limitations. Some could be worked around, others where showstoppers.
Collada may be worth a look. I don't think that it's that good as a format to be read by a 3D engine. It's fine as a general data-exchange format though.
http://www.collada.org/mediawiki/index.php/Main_Page
+1 for Collada. You may also want a custom native binary format for really fast loading (usually just a binary dump of vertex/index buffer data, plus material and skeleton data, and collision data if appropriate).
One trend in the games industry is to support loading a format like collada in the developer build of the engine, but also have a toolchain that exports an optimized version for release. The developer version can update the mesh dynamically, so as artists save changes, the file is automatically reloaded allowing them an (almost) instant WYSIWYG view of their model, but still providing a fully optimised release format.
support Collada well, and then supply good converters to/from the other formats (this might be the hard part). This will give you maximum flexibility. Take a look at C4 engine
Collada is great, but it lives more on the 3D app side of things. ie it's best used for transferring 3D data between applications, not loading 3D data from within a games engine. Have you looked into Lua? It's widely used in games because its a scripting language that's both ridiculously quick (perfect for games) and very flexible (can be used to represent whatever data you need for your engine).

Resources