Interactive paint corrections on a raster image

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Interactive paint corrections on a raster image


I have tried to develop a simple method of correcting some artefacts in an
image with R. Before proceeding further with image analysis.

An example of my attempt:


im <- load.example('coins')

imr <- as.raster(im)


sel <- locator(n=1)


x1 <- floor(sel$x)

x2 <- x1+10

y1 <- floor(sel$y)

y2 <- y1+10

imr[y1:y2,x1:x2] <- "#FFFFFF"

# I want this correction to be immediately visible without the need for

imr2 <- imr


This works. But I want to improve it to be more flexible inmaking
interactive corrections.
The improvements that I am thinking of are:

1.       Instead of a rectangular area, I want a circular one. And I want
the painting to be visible directly without the need for replotting. I
would like to be able to enlarge slowly the area where I need to do the
corrections (with multiple small corrections to cover an irregular area).
This may require other techniques. For example, with shiny. I know almost
nothing about it. Would appreciate some tips to get started.

2. I am having trouble with specification of colour in the hexadecimal
mode. How can I convert a grayscale image to a numerical mode? I would like
to be able to have corrections made with the intensity in a certain range.
How do I access the colour values at specific locations? I did not succeed
with the getValues function (in a different image).

> getValues(imi3,nrows=seq(917,1017,1),ncols=seq(1119,1219,1))

Error in (function (classes, fdef, mtable)  :

  unable to find an inherited method for function ‘getValues’ for signature
‘"raster", "missing", "numeric"’

I would like to know my mistake here .

I will appreciate all help that I can get.

Thanking you,


        [[alternative HTML version deleted]]

[hidden email] mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.