0

I am using HDF satellite data to retrieve bands from that I am concluding different vegetation indices. Every band in hdf data is in grey colour format, its a grey colour scale image. After HDF data processed I can convert into colour by using colour map (I am using jet for colourmap). My doubt is how to convert greyscale image into colourmaped while using imwrite. How to use colourmap within imwrite. I have tried many times, but the output is only in full blue colour, this spoil the output image. Please help me to do this.

prabu
  • 131
  • 2
  • 5
  • 11

2 Answers2

0

Try using the ind2rgb function before using imwrite if you want to save to a format like .jpg, but if you are using an indexing image format (e.g. .png) you can just use imwrite directly as shown in the docs:

imwrite(X, map, filename)

where X is your greyscale image, map is your colourmap (i.e. jet) and filename is the is the name of the image you want to save ending in .png

Dan
  • 45,079
  • 17
  • 88
  • 157
  • imwrite(NDVI,ind2rgb,'/var/www/html/uploads/mynewwwww.jpg','jpg'); Error using ind2rgb (line 17) Not enough input arguments. – prabu Sep 29 '14 at 07:05
  • imwrite(NDVI,jet,'/var/www/html/uploads/mynew2www.jpg'); Even now I am getting full blue screen image. If i use colourmap on greyscale image which is already imwrite to grey scale image then i got correct colour output. that means imwrite grey scale image to 1.jpg, after that convert that 1.jpg to colourmap. It works.. – prabu Sep 29 '14 at 07:12
  • @prabu please read the docs for `ind2rgb`, you are not using it even remotely correctly. It is a function that requires parameters and outputs an RGB image not a map! With regards to your second attempt, I specifically said to use `.png` and ***NOT*** `.jpg` – Dan Sep 29 '14 at 07:20
  • is .png for output image? it means imwrite(NDVI,jet,'/var/www/html/uploads/mynew2www.png'); here NDVI is processed image (grey scale) jet is for colourmap. – prabu Sep 29 '14 at 07:34
  • @prabu can you be specific? Also what is the range of values of `NDVI`? – Dan Sep 29 '14 at 09:00
  • width: 1243 pixels Height: 6120 pixels Image. – prabu Sep 29 '14 at 09:57
  • @prabu that is not relevant. If you don't explain (a) what is "not working" *exactly* and (b) what the range of the *values* inside `NDVI` is, i.e. are they integers from 0-255, are they doubles from `0-1`, something in between??? then it is impossible to help you – Dan Sep 29 '14 at 10:00
  • actually that ndvi is calculated from formula NIR-RED/NIR+RED , these are bands from HDF data (oceansat satellite data). HDF is full of binary values. it consists different bands of information from that i want to calculate NDVI. Calculated but its in greyscale because of binary 0 1. single HDF data size is ~ 200 MB. – prabu Sep 29 '14 at 10:41
  • @prabu if it's binary then why would you want to apply a colormap?? If it's a logical matrix then you should convert to double using either `NDVI = NDVI*1` or `NDVI = NDVI*255` and you should probably use a binary colormap like `jet(2)` – Dan Sep 29 '14 at 10:43
0

Why use imwrite? You can use imshow.

Example:

  1. imshow(im)

enter image description here

  1. imshow(im,'Colormap',jet(255))

enter image description here

With reference: http://www.alecjacobson.com/weblog/?p=1655

lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • No, I want to write that image to show in web interface. It's web based application. – prabu Sep 29 '14 at 07:03
  • Mr Lakesh, above you said is right. But when using imwrite the output stored image is full of blue colour. colourmap is not working with imwrite. – prabu Sep 29 '14 at 07:07