Dear stackexchange world. I would like to ask a question about a problem I am facing with a small program that I am writing in R. I have written a code that lets you import an image and manipulate it with the EBImage() library. I use gWidgets() library so the user can do dynamic manipulation. The code is this one:

library("EBImage")
library("gWidgets2")
setwd(choose.dir())
imageinput<-file.choose()
image<-readImage(imageinput)

##defininig the color mode
colorimage<-c(Greymode="gray",RGBmode="rgb")


updateImage <-function (h,...) {

image1<-((svalue(brightness)+image*svalue(contrast))^(svalue(gamma)))
image2<-channel(image1,colorimage[svalue(colormode)])
display(image2)
}

colormode <- gradio(names(colorimage), horizontal=FALSE,handler=updateImage)
brightness<-gslider(from=-1,to=1,by=.1, value=0,handler=updateImage)
contrast <- gslider(from=0,to=10,by=.1, value=1,handler=updateImage)
gamma <- gslider(from=0,to=10,by=0.1, value=1,handler=updateImage)


window <- gwindow("Image Editing")


BigGroup <- ggroup(cont=window)
group <- ggroup(horizontal=FALSE, container=BigGroup)
tmp <- gframe("Colormode", container=group)
add(tmp, colormode)
tmp <- gframe("Brightness", container=group)
add(tmp, brightness, expand=TRUE)
tmp <- gframe("Contrast", container=group)
add(tmp, contrast, expand=TRUE)
tmp <- gframe("Gamma", container=group)
add(tmp, gamma, expand=TRUE)

But I am facing a problem (as I posted in a previous question, but I solved some issues and I thought it would be good to repost a new one with better code and many problems solved). The problem is that I cannot display in the gWidgets GUI I have constructed the image and how it is dynamically edited. Although there is a way to see the image with the display() function of the EBImage package, it is not the one I want because it is displayed in the web browser and not in the GUI.

I would appreciate if someone has any idea what I could do to solve this problem.

有帮助吗?

解决方案

The script is finished and its working thank to suggestions of John Verzani Stéphane Laurent. It was a bit tricky but at the end it worked! the code is this:

library("EBImage")
library("gWidgets2")
setwd(choose.dir())
imageinput<-file.choose()
image<-readImage(imageinput)

##defininig the color mode
colorimage<-c(RGBmode="rgb",Greymode="gray")


updateImage <-function (h,...) {
image1<-((svalue(brightness)+image*svalue(contrast))^(svalue(gamma)))
image2<-channel(image1,colorimage[svalue(colormode)])
imageout<-writeImage(image2,"imageout.jpeg")
svalue(img)<-"imageout.jpeg"
}

colormode <- gradio(names(colorimage), horizontal=FALSE,handler=updateImage)
brightness<-gslider(from=-1,to=1,by=.1, value=0,handler=updateImage)
contrast <- gslider(from=0,to=10,by=.1, value=1,handler=updateImage)
gamma <- gslider(from=0,to=10,by=0.1, value=1,handler=updateImage)


window <- gwindow("Image Editing")

BigGroup <- ggroup(cont=window)
group <- ggroup(horizontal=FALSE, container=BigGroup)
tmp <- gframe("Colormode", container=group)
add(tmp, colormode)
tmp <- gframe("Brightness", container=group)
add(tmp, brightness, expand=TRUE)
tmp <- gframe("Contrast", container=group)
add(tmp, contrast, expand=TRUE)
tmp <- gframe("Gamma", container=group)
add(tmp, gamma, expand=TRUE)
img <- gimage(imageinput,container=BigGroup)

There should be created a new frame that would contain the graphics (gimage) but the value of the image displayed should be renewed after every editing. So the svalue should be in the function.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top