fitBackground {DASplusR} | R Documentation |
Read a PNM or PostScript-image into R and fit it to 2-dimensional spatial data
GUI to load and fit a background map
'fitBackground' workhorse for FitBackgroundGUI and function for batch mode
convertBackground(filename,type=c("pnm","ps")) fitBackground(image.coordinates,data.coordinates,image,model.type="sim")
image.coordinates |
n x 2- Coordinate matrix of the reference points on the image |
data.coordinates |
n x 2- Coordinate matrix of the reference points of the data |
image |
Image object (class=Picture or class=SpatialPointsPictureFrame) |
model.type |
Model type("sim","affine","nonlinear","robustsim") |
filename |
string giving the name of the file |
type |
string giving the type of the image to convert |
The functions fit the background map by reference points.
At first we have to select reference points by clicking on the 'Add/Identify a Reference Point'-Button. The first click on the graphic device should be on the reference point of the background map, the second click is to identify the corresponding data point.
Afterwards we have to click the 'OK'-Button to estimate the model (The model type is set by the radiobuttons 'Transformation Type').
Now the data and the fitted map are plotted. We can now add more reference points for a better fitting, delete wrong reference points or move on of the reference points on the map.
To delete a pair of reference points we have to click on a radiobutton in the column 'Delete' and the desired row.
To move a reference point on the background map (Reference points on the data cannot be moved, because 'identify()' is used) we have to select a point by clicking on a radiobutton in the column 'Move'. Now we can move the point by clicking at the arrow-buttons. We can specify the length of each step by changing the number in the text-input-field placed underneath the arrow-buttons.
We can go back to the beginning by clicking on the 'Reset'-Button.
To delete all points, but keep the actual background map use the 'Delete All'-Button.
This process is supposed to be iterative.
If we have a satisfying fitting of the background map, we have to press the 'Save Background'-Button to save the map.
With the menu entry 'Background/Load' a previously saved map can be loaded into the workspace.
For reading PostScript-Images GhostScript has to be available.
Using Windows: Upon request the binary directory of your GhostScript installation has to be selected
Alexander Kowarik, TU Vienna, February 2008
### Background map from a Postscript-Image, plotted on a worksheet with two ### frames, left after a similarity transformation, right after an additional ### nonlinear transformation data(KOLA95_Chor, package="DASplusR7") activeDataSet("KOLA95_Chor") worksheet(25,18) worksheetFrame(0,0,12.5,18,col="transparent") worksheetFrame(12.5,0,25,18,col="transparent") filename <- paste(searchpaths()[grep("DASplusR",searchpaths())], "/data/background_vector.ps",sep="") convertBackground(filename,type="ps") activeFrame( 1 ) .background <- fitBackground(image.coordinates=matrix(c(6142.97,4064.9,880.16, 6388.9,3216.45,4342.16,5545.7,1345.59,1542.09,6061.5), ncol=2),data.coordinates=matrix(c(833075,648300,372602,853146,575250,7694720, 7810800,7403610,7421710,7859150),ncol=2), image=justDoIt(".background"),model.type="sim") plot(.background,xaxt="n",yaxt="n",bty="n") symbolMapDAS(dataset=KOLA95_Chor,x="XCOO",y="YCOO",var="Al",level="Boxplot", symbolset="EDA",title="",xlabel="similarity", ylabel="", cex.xlab = "1",cex.ylab="1",font.xlab="1",font.ylab="1",margin=c(5,4,4,2)+0.1, xMin=NA, xMax=NA, yMin=NA, yMax=NA, x.grid=FALSE, x.grid.type=1, x.grid.color="black", x.grid.width=1, y.grid=FALSE, y.grid.type=1, y.grid.color="black", y.grid.width=1, x.log=FALSE, y.log=FALSE, frame=TRUE, addP=TRUE) axis(1,labels=TRUE,font=1,cex.axis=1) axis(2,labels=TRUE,font=1,cex.axis=1) activeFrame( 2 ) .background <- fitBackground(image.coordinates=matrix(c(840606.92,648639.11, 357992.61,864887.66,570246.7,735162.82,727776.5,7692074.92, 7801624.15,7413184.51,7434508.09,7848598.34,7385747.72,7738355.21), ncol=2), data.coordinates=matrix(c(833075,648300,372602,853146,575250,728208,726451, 7694720,7810800,7403610,7421710,7859150,7373050,7742860),ncol=2),image= # justDoIt(".background"),model.type="nonlinear") .background,model.type="nonlinear") plot(.background,xaxt="n",yaxt="n",bty="n") symbolMapDAS(dataset=KOLA95_Chor,x="XCOO",y="YCOO",var="Al",level="Boxplot", symbolset="EDA",title="",xlabel="nonlinear",ylabel="", cex.xlab = "1", cex.ylab="1",font.xlab="1",font.ylab="1",margin=c(5,4,4,2)+0.1,xMin=NA, xMax=NA, yMin=NA, yMax=NA, x.grid=FALSE, x.grid.type=1, x.grid.color="black", x.grid.width=1, y.grid=FALSE,y.grid.type=1,y.grid.color="black", y.grid.width=1,x.log=FALSE, y.log=FALSE,frame=TRUE,addP=TRUE) axis(1,labels=TRUE,font=1,cex.axis=1) axis(2,labels=TRUE,font=1,cex.axis=1) ### Background map from a PNM-Image worksheet(18,25) worksheetFrame(0,12.5,18,25,col="transparent") worksheetFrame(0,0,18,12.5,col="transparent") data(KOLA95_Chor, package="DASplusR7") activeDataSet("KOLA95_Chor") filename <- paste(searchpaths()[grep("DASplusR",searchpaths())], "/data/background_pixel.pnm",sep="") convertBackground(filename,type="pnm") .background<-fitBackground(image.coordinates=matrix(c(317.87,386.21,481.44, 72.5,501.61,679.03,621.08,576.77,321.11,334.75),ncol=2), data.coordinates=matrix(c(648300,726451,833075,372602,853146,7810800, 7742860,7694720,7403610,7421710),ncol=2), image=justDoIt(".background"),model.type="affine") activeFrame(1) plot(.background) symbolMapDAS(dataset=KOLA95_Chor,x="XCOO",y="YCOO",var="Al",level="Boxplot", symbolset="EDA",title="",xlabel="", ylabel="", cex.xlab = "1", cex.ylab="1", font.xlab="1",font.ylab="1",margin=c(5,4,4,2)+0.1, xMin=NA, xMax=NA, yMin=NA, yMax=NA, x.grid=FALSE, x.grid.type=1, x.grid.color="black", x.grid.width=1, y.grid=FALSE,y.grid.type=1,y.grid.color="black",y.grid.width=1,x.log=FALSE, y.log=FALSE,frame=TRUE,addP=TRUE) axis(1,labels=TRUE,font=1,cex.axis=1) axis(2,labels=TRUE,font=1,cex.axis=1) activeFrame(2) symbolMapDAS(dataset=KOLA95_Chor,x="XCOO",y="YCOO",var="Al",level="Boxplot", symbolset="EDA",title="",xlabel="", ylabel="", cex.xlab = "1", cex.ylab="1", font.xlab="1",font.ylab="1",margin=c(5,4,4,2)+0.1, xMin=NA, xMax=NA, yMin=NA, yMax=NA, x.grid=FALSE, x.grid.type=1, x.grid.color="black", x.grid.width=1, y.grid=FALSE,y.grid.type=1,y.grid.color="black",y.grid.width=1,x.log=FALSE, y.log=FALSE,frame=TRUE,addP=FALSE) plot(.background,xaxt="n",yaxt="n",bty="n",add=TRUE) symbolMapDAS(dataset=KOLA95_Chor,x="XCOO",y="YCOO",var="Al",level="Boxplot", symbolset="EDA",title="",xlabel="", ylabel="", cex.xlab = "1", cex.ylab="1", font.xlab="1",font.ylab="1",margin=c(5,4,4,2)+0.1, xMin=NA, xMax=NA, yMin=NA, yMax=NA, x.grid=FALSE, x.grid.type=1, x.grid.color="black", x.grid.width=1, y.grid=FALSE,y.grid.type=1,y.grid.color="black",y.grid.width=1,x.log=FALSE, y.log=FALSE,frame=TRUE,addP=TRUE)