[R] Interactive paint corrections on a raster image

Vivek Sutradhara v|vek@utr@ @end|ng |rom gm@||@com
Tue Aug 11 19:50:34 CEST 2020


Hi,

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:

library(imager)

im <- load.example('coins')

imr <- as.raster(im)

plot(imr)

sel <- locator(n=1)

sel

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
replotting

imr2 <- imr

plot(imr2)


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,

Vivek

	[[alternative HTML version deleted]]



More information about the R-help mailing list