本文介绍了无法使用ImageMagick创建NDVI图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四张单独的图片 -






或者,如果红色和NIR是RGB图像中的前两个通道(即 ImageMagick 会将它们称为红色和绿色通道):

 转换RGB.tif -fx'(ur-ug)/(u.r + u。 g + 0.001)' -  normalize -compress lzw NDVI.tif 

这里我使用 ur 引用第一个图像的第一个通道e和 ug 引用第一张图片的第二个频道。






-fx 方法功能非常强大,但速度非常慢。下面这个方法应该给你相同的答案,但我没有彻底检查:

  convert 4-projected.tif  - 写MPC:red + delete \ 
5-projected.tif -write MPC:NIR + delete \
\(mpc:red mpc:NIR -evaluate-sequence subtract \)\
\(mpc:red mpc:NIR -evaluate-sequence add \)\
-evaluate-sequence divide -normalize -compress lzw NDVI.tif






如果要使用假色对图像进行着色,可以生成颜色查找表(CLUT)并将NDVI图像中的灰度值映射到这些颜色。所以,假设您想要将NDVI图像中最暗的黑色映射为黑色,将相当暗的值映射为红色,将相当明亮的值映射为橙色,将最亮的值映射为绿色,您可以将这样的CLUT映射为:

 转换xc:黑色xc:红色xc:橙色xc:lime + append clut.png 


并将其应用于灰度上面的结果是这样的:

 转换NDVI.tif -normalize clut.png -clut falsecolour.jpg 


如果你想让橙色和绿色的色调更长(更普遍),你可以改变它们的长度以使它们更长CLUT:

  convert -size 30x1 xc:black -size 40x1 xc:red -size 80x1 xc:orange -size 100x1 xc :lime + append clut.png 


然后重新应用CLUT:

 转换NDVI.tif -normalize clut.png -clut result.jpg 

I have four separate images - 2-projected.tif, 3-projected.tif, 4-projected.tif and 5-projected.tif. These are four Landsat images. Image 2-projected.tif corresponds to blue channel, image 3-projected.tif - to green channel, image 4-projected.tif - to red channel, and 5-projected.tif - to infrared. Now I want to create NDVI image. To do this, I first create a combined RGB image, using ImageMagic:

$ convert 4-projected.tif 3-projected.tif 2-projected.tif -combine RGB.tif

So far, so good. And then I try to follow a command from this tutorial, which is supposed to create NDVI image. I do it like so:

$ convert 5-projected.tif RGB.tif -channel RGB -fx '(u.r-v.r)/(u.r+v.r+0.001)' -normalize NDVI.tif

But as a result, I get these error messages:

I'm not sure how can I fix it.

解决方案

The two bands of interest are the red and the NIR and the formula for NDVI is:

NDVI = (NIR-red)/(NIR+red)


You have two options. First off, if you have the red and the NIR in two separate, single channel images, you can do:

convert red.tif NIR.tif -fx '(u.r-v.r)/(u.r+v.r+0.001)' -normalize -compress lzw NDVI.tif

Here, I am using u.r to refer to the first channel of the first image and v.r to refer to the first channel of the second image.


Alternatively, if the red and NIR are the first two channels in an RGB image (i.e. ImageMagick would call them the red and green channels):

convert RGB.tif -fx '(u.r-u.g)/(u.r+u.g+0.001)' -normalize -compress lzw NDVI.tif

Here I am using u.r to refer to the first channel of the first image and u.g to refer to the second channel of the first image.


The -fx method is extremely powerful, but notoriously slow. This method below should give you the same answer, but I have not checked it too thoroughly:

convert 4-projected.tif -write MPC:red +delete           \
        5-projected.tif -write MPC:NIR +delete           \
       \( mpc:red mpc:NIR -evaluate-sequence subtract \) \
       \( mpc:red mpc:NIR -evaluate-sequence add      \) \
       -evaluate-sequence divide -normalize -compress lzw NDVI.tif


If you want to colourise the image with false colour, you could generate a Colour Lookup Table (CLUT) and map the grayscale values in the NDVI image to those colours. So, let's say you wanted to map the darkest blacks in your NDVI image to black, the quite dark values to red, the quite bright values to orange and the very brightest values to green, you could make a CLUT like this:

convert xc:black xc:red xc:orange xc:lime +append clut.png

and apply it the greyscale result from above like this:

convert NDVI.tif -normalize clut.png -clut falsecolour.jpg

If you want to make the orange and green tones longer (more prevalent), you can alter their lengths to make them longer in the CLUT:

convert -size 30x1 xc:black -size 40x1 xc:red -size 80x1 xc:orange -size 100x1 xc:lime +append clut.png

Then re-apply the CLUT:

convert NDVI.tif -normalize clut.png -clut result.jpg

这篇关于无法使用ImageMagick创建NDVI图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 08:03
查看更多