Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Image Array Error' topicStudent Support Forum > General > "Image Array Error"

Next Comment >Help | Reply To Topic
Author Comment/Response
Melissa
12/06/11 09:28am

Hello,

I am trying to work with creating and manipulating images in Mathematica. I start out with creating an image that is 800 by 1800 with the two methods rowCreation and rowAddition and every pixel is black.

rowCreation[] := Module[{}, row1 = {};
For[p = 0, p < 1800, p++, row1 = Append[row1, {0, 0, 0}]];]

rowAddition[] := Module[{}, total = {};
For[p = 0, p < 800, p++, total = Append[total, row1]];]

Then I randomly select a "point" (var1, var2) and turn that point a different color: green.
var1 = Random[Integer, {1, 799}]
var2 = Random[Integer, {1, 1799}]
total[[var1]][[var2]] = {0, 1, 0};

This is where I am having trouble. I have a list of numbers 0-3 called mods and for every value in that list I am trying to change a pixel to green.

For[ i = 0, i < Length[mods], i++,
onemod = Part[mods, i];
If[onemod == {0}, var1 = Floor[var1 / 2]; var2 = Floor[var2 / 2];
total[[var1]][[var2]] = {0, 1, 0}];
If[onemod == {1}, var1 = Floor[var1 / 2];
var2 = Floor[(var2 + 1800) / 2]; total[[var1]][[var2]] = {0, 1, 0}];
If[onemod == {2}, var1 = Floor[(var1 + 800) / 2];
var2 = Floor[var2 / 2]; total[[var1]][[var2]] = {0, 1, 0}];
If[onemod == {3}, var1 = Floor[(var1 + 800) / 2];
var2 = Floor[(var2 + 1800) / 2]; total[[var1]][[var2]] = {0, 1, 0}];
]

These are some errors I get:
Set::partd: Part specification total[[var1,var2]] is longer than depth of object. >>
Part::partd: Part specification List[[1435]] is longer than depth of object. >>
Set::partd: Part specification total[[var1,var2]] is longer than depth of object. >>
Part::partd: Part specification List[[717]] is longer than depth of object. >>

When I try to display the image:
image = Image[total, Magnification -> 1];
image
I get an error:

Image::imgarray: The specified argument {{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},<<1750>>},<<49>>,<<750>>} should be an array of rank 2 or 3 with machine-sized numbers.

I am not sure what the problem is because sometimes it will work when the length of mods is 4000 or 5000 or 6000 but other times it will not work. Any help would be appreciated! Thanks!

URL: ,

Subject (listing for 'Image Array Error')
Author Date Posted
Image Array Error Melissa 12/06/11 09:28am
Re: Image Array Error Melissa 12/07/11 9:06pm
Re: Image Array Error Quinn McKinsey 12/08/11 06:49am
Next Comment >Help | Reply To Topic