Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to assign random image files that undergo rescaling to a list of variable names. The images I'm trying to assign are the result of mapping the ImageResize function of two arguments to the Randomly generated images, where the 2nd argument has a fixed value. However when I assign the values to a list of variables, the Scaled[50] argument is not being applied to the images. Thanks.

I store 15 random images in variables tmp[1], tmp[2], ... using a Do statment and recall them using another statement:

Do[tmp[i] = Image[RandomReal[1, {8, 12, 3}]], {i, Range[1, 15]}];
tmp /@ Range[1, 15]

(See Assigning values to a list of variable names)

Now I want to Scale all the images 50x and store them in a list of variables. It can overwrite the tmp variables, but for simplicity I'll use new variables:

Do[var[j] = ImageResize[#, Scaled[50]] & /@ tmp[j], {j, Range[1, 15]}];

(See Mapping a function of two arguments where the 2nd arg has a fixed value)

When I recall them using

var /@ Range[1,15]

they are not scaled, it is the same images as in tmp /@ Range[1,15] unscaled.

This code produces the desired result on a single image

var[1]=ImageResize[tmp[1], Scaled[50]]

so I'm not sure why the second Do statment does not produce the desired list of rescaled images. If there is a way to do it in the initial creation of the images (in the first Do statement) that is better.

share|improve this question
    
Use the Do as Do[var[j] = ImageResize[tmp[j], Scaled[50]], {j, Range[1, 15]}]; or, better, use @belisarius suggestion. Also, var=Table[ImageResize[j, Scaled[50]], {j, tmp /@ Range[1, 15]}]. –  b.gatessucks Jan 9 at 9:37

1 Answer 1

up vote 2 down vote accepted
tmp = RandomImage[1, {12, 8}, ColorSpace -> "RGB"] & /@ Range[15]; 
var = ImageResize[#, Scaled[50]] & /@ tmp;
var
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.