For loop : mixing iterator with argument of a function

Julia_fun_123
Tue, 16 Aug 2022 20:01:42 +0000
General Usage

Hello everyone.

I am using Julia 1.7.3 with Jupyter Lab, and I have this code (which is partially taken from this link : Converting image colors · ColorSchemeTools) :

using FileIO, ColorSchemes, ColorSchemeTools, Images

img = load("julia-logo-square.png")
img_rgb = RGB.(img)

convertedimage_4 = convert_to_scheme(ColorSchemes.PiYG_4, img_rgb)
convertedimage_5 = convert_to_scheme(ColorSchemes.PiYG_5, img_rgb)
convertedimage_6 = convert_to_scheme(ColorSchemes.PiYG_6, img_rgb)

IJulia.display(convertedimage_4)
IJulia.display(convertedimage_5)
IJulia.display(convertedimage_6)

However, instead of typing :

convertedimage_4 = convert_to_scheme(ColorSchemes.PiYG_4, img_rgb)
convertedimage_5 = convert_to_scheme(ColorSchemes.PiYG_5, img_rgb)
convertedimage_6 = convert_to_scheme(ColorSchemes.PiYG_6, img_rgb)

IJulia.display(convertedimage_4)
IJulia.display(convertedimage_5)
IJulia.display(convertedimage_6)

I’d like to execute the following pseudo-code :

for i in 4:6
    convertedimage_i = convert_to_scheme(ColorSchemes.PiYG_i, img_rgb)
    IJulia.display(convertedimage_i)
end

where the iterator i will go from 4 to 6 of course.

This is easier when done with strings, but in this situation, I am a bit stuck.

Anybody have an idea on how to solve this (it’s basic I think, but I’m not sure how to do this in Julia) ?

5 posts - 4 participants