AVA
AVA

Reputation: 2558

How to update colors of an image pixels in julia?

Objective: to change color intensity of pixels
Code:

using Images, ImageView;

function updateColors(path::String)
    if isfile(path)
        img = load(path);  
        chnlView = channelview(img);
        chnlView[chnlView .> 0.7] = 0.9;
        imshow(img);
    else
        info("Error: Image Not Found!");
    end
end

#By Prof.Bogumił Kamiński
function quit()
    print("Press q to quit!");
    while true
        opt = getChar();
        if opt == 'q'
            break
        else
            continue
        end
    end
end

#By Prof.Bogumił Kamiński
function getChar()
    ret = ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), stdin.handle, true)
    ret == 0 || error("unable to switch to raw mode")
    c = read(stdin, Char)
    ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), stdin.handle, false)
    c
end

updateColors("/opt/julia/pictures/test.jpg");
quit();

Error:

no method matching setindexshape(::Float64, ::Int64)

Please help me in resolving the issue!

Upvotes: 1

Views: 271

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69949

You should broadcast the assignment operation like this:

chnlView[chnlView .> 0.7] .= 0.9

Upvotes: 3

Related Questions