Image analysis in R: matching the TIFF image with the corresponding point pattern match
so I'm using spatstat package in R, and analyzing a TIFF segmentation mask image as well as the corresponding planar point pattern (using only the X,Y coordinates of the segmented object centroids).
For clarity, the planar point pattern object contains X,Y coordinates (centroids) of the objects from the TIFF segmentation image. I am trying to plot the X,Y coordinates in a layered manner which shows the mask and the centroids.
However when I load the TIFF image that contains a visual image of the boundary points the window. The dimensions of the TIFF image is 2800X2800
vim integer-valued pixel image 2800 x 2800 pixel array (ny, nx) enclosing rectangle: [0, 2800] x [0, 2800] micrometer
The corresponding point patterns range from (X: 2X700) and Y: (2X700).
types$RB Planar point pattern: 835 points window: rectangle = [2.1364, 699.1579] x [1.5143, 699.3214] units (one unit = 2 micrometer)
How do I align up these two coordinate spaces in R using 'spatmat' or another image analysis package?
How do I align the coordinates of the centroids over the segmentation mask?
I could try to rescale the types$RB object so that it has the same dimensions as the TIFF image, however this does not really look like a match.
Update: For this approach, I think it is required to create a shape file from the TIFF file. and then begin overlaying the centroids (X,Y) coordinates over the shape file derived from a TIFF plot.
See also questions close to this topic
How to move polygon to different list in SpatialPolygons object in R?
rtuwith a list of 161 polygons. In first list there's 146
Polygons. I move one polygon to that list (trying to append) from the same object: list of index 92. At the end I delete that row.
r = rtu@polygons[]@Polygons rp <- Polygons(r, 1) ps = c(rtu@polygons[]@Polygons, rp@Polygons) rtu@polygons[]@Polygons <- ps rtu@polygons[] <- NULL
At this point everything looks ok. The structure have now 147
Polygonsand plot is ok. But while I go further and try:
this throws error:
> ov = over(rtu, rtu) Error in RGEOSBinPredFunc(spgeom1, spgeom2, byid, func) : lengths of comment and Polygons slot differ
I suppose my transformation was wrong at some point but where? I guess there's some function to be better with such transformations. Please help me find this error.
How can I model fly movement (with three points: head, midpoint, and tail) in R and deduce from the output data other behavioral descriptors?
My data consists of x and y coordinates of a fly larva's head, tail, and midpoint at each frame of recording. How do I create a model of each point's movement and connect the points with lines (head to midpoint, midpoint to tail) so that I can picture the body parts' positions at each frame (essentially making a movie)? I am analyzing fly larvae behavior after they have been genetically manipulated against wild-type controls, and trying to deduce from my outputs (I have a program to track the behavior of the larva in a standard arena): the curvature (in degrees) at each frame, the speed of movement between each frame of each body part, which body parts move most frequently, and how frequently the larva changes direction.
I have searched stack overflow and r's help website for information on how to compute these things, particularly the curvature, since most of the analyses require that all three points (head, midpoint, and tail) be considered simultaneously.
I hope to obtain each of the above parameters for each frame of my recording.
hql spatial ST_MakeEnvelope
Just a "simple" question:
how is the syntax of postgis function ST_MakeEnvelope() in Hibernate HQL?
I couldn't find any documentations after searching 2 hours :/
thanks in advance
Connect the chart to sp in mvc5
I implemented a project with the language mvc 5, There are a number of charts in that project that I uploaded from the site https://www.highcharts.com in the project. The required sps are written in databases، Please advise how to call data base information on charts
Identifying and changing coordinate reference system (LCC and rotated lat/long)
I have ncdf4 data that all comes from the same project and are on a 12 km grid, but some files have different projections. The data are either projected in some form of LCC in km, or rotated lat/long in degrees.
I am normally quite familiar with dealing with projections in R and GIS but this data is besting me. I will explain with an example of a couple of files. I start by plotting some of the data which I have previously extracted so that the issues are clear.
I have saved my data on transferXL here: https://transferxl.com/08K1GjnvPKGMp
> > pacman::p_load(tidyverse, data.table, ncdf4, lubridate, sp, rgdal) > > files = list.files("C:/Users/av57/Desktop/Example", full.names = TRUE)[-1]; files  "C:/Users/av57/Desktop/Example/mrro_EUR-11_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_CLMcom-CCLM4-8-17_v1_mon_195001-195012.nc"  "C:/Users/av57/Desktop/Example/mrro_EUR-11_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_CNRM-ALADIN53_v1_mon_195001-195012.nc"  "C:/Users/av57/Desktop/Example/ncdfData.RDS" > > > # Extracted data > dt <- readRDS(files[]) %>% as.data.table; dt x y mrro ncFile 1: -19.905 0.055 8.932733 1 2: -19.795 0.055 8.938593 1 3: -19.685 0.055 8.924219 1 4: -19.575 0.055 8.918390 1 5: -19.465 0.055 8.920496 1 --- 23225: 2237.500 4237.500 5.949244 2 23226: 2250.000 4237.500 6.011243 2 23227: 2262.500 4237.500 5.969373 2 23228: 2275.000 4237.500 5.951464 2 23229: 2287.500 4237.500 5.895301 2 > dt %>% + ggplot(aes(x = x, y = y, colour = mrro)) + + geom_point() + + theme_minimal() + + scale_colour_viridis_c() + + facet_wrap(~ncFile, scales = "free") >
I start with the second ncdf file as there is a lot of information about the coordinate system in the header.
> # File 2 > nc2_lcc <- files[] %>% nc_open(); nc2_lcc File C:/Users/av57/Desktop/Example/mrro_EUR-11_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_CNRM-ALADIN53_v1_mon_195001-195012.nc (NC_FORMAT_NETCDF4_CLASSIC): 5 variables (excluding dimension variables): double lon[x,y] standard_name: longitude long_name: longitude units: degrees_east double lat[x,y] standard_name: latitude long_name: latitude units: degrees_north float mrro[x,y,time] standard_name: runoff_flux units: kg m-2 s-1 _FillValue: 1.00000002004088e+20 grid_mapping: Lambert_Conformal coordinates: lat lon cell_methods: time: mean long_name: total runoff char Lambert_Conformal grid_mapping_name: lambert_conformal_conic longitude_of_central_meridian: 10.5 standard_parallel: 49.5 latitude_of_projection_origin: 49.5 double time_bnds[tbnds,time] 4 dimensions: x Size:453 units: km long_name: x coordinate of projection standard_name: projection_x_coordinate axis: X y Size:453 units: km long_name: y coordinate of projection standard_name: projection_y_coordinate axis: Y time Size:12 *** is unlimited *** standard_name: time units: days since 1949-12-01 calendar: gregorian bounds: time_bnds axis: T long_name: time tbnds Size:2 21 global attributes: CDI: Climate Data Interface version 1.5.6 (http://code.zmaw.de/projects/cdi) Conventions: CF-1.4 institution: Centre National de Recherches Meteorologiques experiment_id: historical experiment: Historical run with GCM forcing driving_model_ensemble_member: r1i1p1 driving_experiment_name: historical institute_id: CNRM project_id: CORDEX CORDEX_domain: EUR-11 product: output references: http://www.cnrm-game.fr/spip.php?rubrique69&lang=en creation_date: 2014-06-19 18:32:18 CDO: Climate Data Operators version 18.104.22.168 (http://code.zmaw.de/projects/cdo) rcm_version_id: v1 comment: CORDEX Europe ALADIN5.3 0.5 deg CNRM-CERFACS-CNRM-CM5 L31: EUC12-2.00 contact: email@example.com frequency: mon driving_experiment: CNRM-CERFACS-CNRM-CM5, historical, r1i1p1 driving_model_id: CNRM-CERFACS-CNRM-CM5 model_id: ALADIN53
The code I use to convert and check my projection is as follows:
crs <- CRS("+proj=lcc +lon_0=10.5 +lat_0=49.5 +lat_1=49.5 +units=km") # Info from header p <- dt %>% filter(ncFile == 2) %>% select(x,y) %>% SpatialPoints(proj4string=crs); p g <- spTransform(p, CRS("+init=epsg:4326")); g # Plot dt %>% filter(ncFile == 2) %>% select(-x,-y) %>% cbind(coordinates(g)) %>% ggplot(aes(x = x, y = y, colour = mrro)) + geom_point() + theme_minimal() + scale_colour_viridis_c()
Clearly, I have missed out something in the projection - but I have no clue what - the UK definitely does not sit at such a jaunty angle on any map I have seen!
The second problem is with the ncdf file that contains the rotated data. My observations are that the angle of the UK is slightly off and the lat~long are not correct (should be in the range of 50,62 and -7.5,1.5). Because I have never worked with this rotated type of data I am very unclear on where I should start.
> nc1_rotated <- files[] %>% nc_open(); nc1_rotated File C:/Users/av57/Desktop/Example/mrro_EUR-11_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_CLMcom-CCLM4-8-17_v1_mon_195001-195012.nc (NC_FORMAT_NETCDF4_CLASSIC): 7 variables (excluding dimension variables): double time_bnds[bnds,time] int rotated_latitude_longitude grid_mapping_name: rotated_latitude_longitude grid_north_pole_latitude: 39.25 grid_north_pole_longitude: -162 north_pole_grid_longitude: 0 float lat[rlon,rlat] standard_name: latitude long_name: latitude coordinate units: degrees_north bounds: lat_vertices float lon[rlon,rlat] standard_name: longitude long_name: longitude coordinate units: degrees_east bounds: lon_vertices float lat_vertices[vertices,rlon,rlat] units: degrees_north float lon_vertices[vertices,rlon,rlat] units: degrees_east float mrro[rlon,rlat,time] standard_name: runoff_flux long_name: Total Runoff comment: "compute the total runoff (including ""drainage"" through the base of the soil model) leaving the land portion of the grid cell." units: kg m-2 s-1 cell_methods: time: mean area: mean where land missing_value: 1.00000002004088e+20 _FillValue: 1.00000002004088e+20 associated_files: gridspecFile: gridspec_land_fx_CLMcom-CCLM4-8-17_historical_r0i0p0.nc grid_mapping: rotated_latitude_longitude coordinates: lat lon 5 dimensions: time Size:12 *** is unlimited *** bounds: time_bnds units: days since 1949-12-01T00:00:00Z calendar: proleptic_gregorian axis: T long_name: time standard_name: time rlat Size:412 units: degrees axis: Y long_name: latitude in rotated pole grid standard_name: grid_latitude rlon Size:424 units: degrees axis: X long_name: longitude in rotated pole grid standard_name: grid_longitude bnds Size:2 vertices Size:4 29 global attributes: institution: Climate Limited-area Modelling Community (CLM-Community) institute_id: CLMcom experiment_id: historical source: CLMcom-CCLM4-8-17 model_id: CLMcom-CCLM4-8-17 contact: firstname.lastname@example.org history: Processing for CORDEX archive at DKRZ (SVN revision 4244 http://svn-mad.zmaw.de/svn/mad/Model/IMDI/tags/cclm/cosmo_090213_4.8_clm17_cordex/util/running) 2014-03-19T07:46:58Z CMOR rewrote data to comply with CF standards and CORDEX requirements. comment: CORDEX Europe RCM CCLM 0.11 deg EUR-11 references: http://www.clm-community.eu/ initialization_method: 1 physics_version: 1 tracking_id: 51729336-d735-4e75-ba14-f3b777dab426 title: CLMcom-CCLM4-8-17 model output prepared for CORDEX historical CORDEX_domain: EUR-11 driving_experiment: CNRM-CERFACS-CNRM-CM5, historical, r1i1p1 driving_model_id: CNRM-CERFACS-CNRM-CM5 driving_model_ensemble_member: r1i1p1 driving_experiment_name: historical rcm_version_id: v1 product: output experiment: historical frequency: mon creation_date: 2014-03-19T07:46:58Z Conventions: CF-1.4 project_id: CORDEX table_id: Table mon (Sept 2013) 1a8d24384e63c141a57dbedfd6710546 modeling_realm: land realization: 1 cmor_version: 2.9.1
Any guidance on how to deal with these projection/conversion problems would be much appreciated.