R raster: the cropped raster had different color (brigtness) from original one?
up vote
0
down vote
favorite
I would like to crop
a multiband raster (4 bands) by spatial polygons (in SpatialPolygonsDataFrame). When I displayed the original and cropped rasters in QGIS, I found that the cropped raster had different colours from the original one. Here is my code:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE)
Partial cropped raster and the corresponding part in original raster in QGIS:
I have no idea how to deal with this issue, any help will be appreciated.
r qgis r-raster
add a comment |
up vote
0
down vote
favorite
I would like to crop
a multiband raster (4 bands) by spatial polygons (in SpatialPolygonsDataFrame). When I displayed the original and cropped rasters in QGIS, I found that the cropped raster had different colours from the original one. Here is my code:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE)
Partial cropped raster and the corresponding part in original raster in QGIS:
I have no idea how to deal with this issue, any help will be appreciated.
r qgis r-raster
What is probably happening is that cropping the image changes the image statistics, which are in turn used byQGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.
– Val
Nov 20 at 8:41
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to crop
a multiband raster (4 bands) by spatial polygons (in SpatialPolygonsDataFrame). When I displayed the original and cropped rasters in QGIS, I found that the cropped raster had different colours from the original one. Here is my code:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE)
Partial cropped raster and the corresponding part in original raster in QGIS:
I have no idea how to deal with this issue, any help will be appreciated.
r qgis r-raster
I would like to crop
a multiband raster (4 bands) by spatial polygons (in SpatialPolygonsDataFrame). When I displayed the original and cropped rasters in QGIS, I found that the cropped raster had different colours from the original one. Here is my code:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE)
Partial cropped raster and the corresponding part in original raster in QGIS:
I have no idea how to deal with this issue, any help will be appreciated.
r qgis r-raster
r qgis r-raster
asked Nov 20 at 8:21
just_rookie
418419
418419
What is probably happening is that cropping the image changes the image statistics, which are in turn used byQGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.
– Val
Nov 20 at 8:41
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45
add a comment |
What is probably happening is that cropping the image changes the image statistics, which are in turn used byQGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.
– Val
Nov 20 at 8:41
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45
What is probably happening is that cropping the image changes the image statistics, which are in turn used by
QGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.– Val
Nov 20 at 8:41
What is probably happening is that cropping the image changes the image statistics, which are in turn used by
QGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.– Val
Nov 20 at 8:41
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
After comparing the two rasters carefully in QGIS, I have found the answer. The issue is related to dataType
argument in the writeRaster
function. So we just need to modify the code like:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
data_type <- unique(dataType(mosaic)) # get data type from original raster;
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE,
datatype = data_type) # set datatype;
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
After comparing the two rasters carefully in QGIS, I have found the answer. The issue is related to dataType
argument in the writeRaster
function. So we just need to modify the code like:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
data_type <- unique(dataType(mosaic)) # get data type from original raster;
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE,
datatype = data_type) # set datatype;
add a comment |
up vote
0
down vote
After comparing the two rasters carefully in QGIS, I have found the answer. The issue is related to dataType
argument in the writeRaster
function. So we just need to modify the code like:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
data_type <- unique(dataType(mosaic)) # get data type from original raster;
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE,
datatype = data_type) # set datatype;
add a comment |
up vote
0
down vote
up vote
0
down vote
After comparing the two rasters carefully in QGIS, I have found the answer. The issue is related to dataType
argument in the writeRaster
function. So we just need to modify the code like:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
data_type <- unique(dataType(mosaic)) # get data type from original raster;
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE,
datatype = data_type) # set datatype;
After comparing the two rasters carefully in QGIS, I have found the answer. The issue is related to dataType
argument in the writeRaster
function. So we just need to modify the code like:
library(raster)
mosaic_shp <- shapefile("mo_clipper.shp")
mosaic <- brick('orthomosaic.tif')
mosaic_sub <- crop(mosaic, extent(mosaic_shp))
data_type <- unique(dataType(mosaic)) # get data type from original raster;
writeRaster(mosaic_sub, 'mosaic_sub.tif', format = "GTiff", overwrite = TRUE,
datatype = data_type) # set datatype;
answered Nov 20 at 9:01
just_rookie
418419
418419
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388831%2fr-raster-the-cropped-raster-had-different-color-brigtness-from-original-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is probably happening is that cropping the image changes the image statistics, which are in turn used by
QGIS
for visualization. Try copying/pasting a layer's style to another and see if the visualization matches. Additionally you can use the value tool to see if the pixel values match.– Val
Nov 20 at 8:41
Check the style that QGIS is using. the pic on the right looks like its only using one band and doing grayscale, but the one on the left is possibly an RGB pseudo colour image which is probably using the first three of your four bands. Check the second one still has four bands.
– Spacedman
Nov 20 at 8:45