Guest User

Untitled

a guest
Dec 16th, 2015
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 2.68 KB | None | 0 0
  1. //Author  :Priyanka Hiranandani NIT Surat    
  2. //TODO: Does not work for uint16 and uint32 type matrices.
  3. function[] =imshow(Image)
  4.    
  5.     global TYPE_DOUBLE;         //retrieving list and creating 3 dimensional matrix out of it
  6.     dimensions=size(Image)
  7.     MaxUInt8 = 2 ^ 8 - 1;
  8.     MaxGrayValue = MaxUInt8; //changed from MaximumGrayValue
  9.  
  10.     if dimensions==3 then
  11.          matSize=size(Image(1));
  12.          r=matrix(Image(1),matSize(1),matSize(2));
  13.          g=matrix(Image(2),matSize(1),matSize(2));
  14.          b=matrix(Image(3),matSize(1),matSize(2));
  15.  
  16.          z(:,:,1)=uint8(r);    //Since Matplot is not working with uint16 and uint32, convert every image to a
  17.          z(:,:,2)=uint8(g);    //8 bit palette.
  18.          z(:,:,3)=uint8(b);    //Note: this will affect the color depth.
  19.  
  20.          [NumberOfRows NumberOfColumns NumberOfChannels] = size(z);
  21.          NumberOfPixels = NumberOfRows * NumberOfColumns;
  22.          Sample = z(1);
  23.          
  24.          //printf("\nType of Sample: ");
  25.      //printf(typeof(Sample)); //DEBUG:
  26.          //printf("\n");   
  27.          
  28.     if type(Sample) == 1 then //type 1 = real/complex matrix of double
  29.              ColorMap = matrix(z, NumberOfPixels, NumberOfChannels);
  30.              disp(ColorMap);
  31.          else
  32.             TypeName = typeof(Sample)
  33.              select TypeName
  34.                  case 'uint8'
  35.                     MaxGrayValue = 2 ^ 8 - 1;
  36.             //printf("uint8\t%d", MaxGrayValue); //DEBUG:
  37.                  case 'uint16'
  38.                     MaxGrayValue = 2 ^ 16 - 1;
  39.             //ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
  40.             //printf("uint16\t%d", MaxGrayValue); //DEBUG:
  41.                  case 'uint32'
  42.                     MaxGrayValue = 2 ^ 32 - 1;
  43.                 //ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
  44.             //printf("uint32\t%d", MaxGrayValue); //DEBUG:
  45.          end;  
  46.          ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
  47.      printf("\nCreated colormap with MaxGrayValue = %d\n", MaxGrayValue); //DEBUG:
  48.          end;      
  49.          Img=z;
  50.  
  51.      //Grayscale
  52.      elseif dimensions==1 then
  53.          matSize = size(Image(1));
  54.          Img=matrix(Image(1),matSize(1),matSize(2));
  55.          Img=Img';
  56.          select typeof(Img)
  57.              case 'uint8'
  58.                 MaxGrayValue = MaxUInt8;
  59.              case 'uint16'  
  60.                 MaxGrayValue = max(Image(:)) ;
  61.              case 'uint32'
  62.                 MaxGrayValue = max(Image(:));                
  63.         end;
  64.      ColorMap = graycolormap(double(MaxGrayValue + 1)); //changed from MaximumGrayValue
  65.      end;
  66.      show(Img,ColorMap);
  67. endfunction
Add Comment
Please, Sign In to add comment