# Why does the function Image not yield a proper output? [closed]

Can I get the exact reason why the function Image doesn't yield a proper output in the below?

Image[TreeForm@{1, 2, 3}]


It shows an error message as below.

Image::imgarray: The specified argument  should be an array of rank 2 or 3 with machine-sized numbers. >>


Is there anyway not to use the function Rasterize for get an image for the TreeForm expression?

• You don't need Image just use TreeForm@{1,2,3} – e.doroskevic Jan 11 '16 at 20:18
• Rasterize works, assuming you want a raster whats wrong with that? – george2079 Jan 11 '16 at 20:36
• Graphics[Inset[TreeForm@{1, 2, 3}]] gets you a graphic object.. (trying to guess what you want.. ) – george2079 Jan 11 '16 at 20:38
• @george2079, or ToExpression@ToBoxes@TreeForm@{1, 2, 3} – Simon Woods Jan 11 '16 at 20:40
• @george2079 Thanks a lot. That is what I wanted! – Smart Humanism Jan 12 '16 at 4:25

## 2 Answers

If you want to get the Graphics representation of TreeForm, you'll need to convert it to boxes first, and then convert these boxes into a Graphics expression. The reason is that TreeForm is a special display form, and is converted directly into boxes for display without actually being evaluated into Graphics by the kernel.

g = TreeForm[{1, 2, 3}] // MakeBoxes // ToExpression;
Head[g] (* -> Graphics *)


You don't mention in the question what you want to do with this output, but if you use Image on this Graphics, you will indeed get a raster image. (Personally, I think this application of Image is misguided. Image is nominally supposed to represent a raster image based on given pixel values, not create one from other objects, which is the job of Raster...)

I will note that the result of Image[g] is identical to that of Rasterize[TreeForm[{1, 2, 3}], "Image"], so it's not clear to me what you hoped to avoid by refusing to use Rasterize here.

Code:

{1, 2, 3} // TreeForm


Output:

Reference:

TreeForm