Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author :Priyanka Hiranandani NIT Surat
- //TODO: Does not work for uint16 and uint32 type matrices.
- function[] =imshow(Image)
- global TYPE_DOUBLE; //retrieving list and creating 3 dimensional matrix out of it
- dimensions=size(Image)
- MaxUInt8 = 2 ^ 8 - 1;
- MaxGrayValue = MaxUInt8; //changed from MaximumGrayValue
- if dimensions==3 then
- matSize=size(Image(1));
- r=matrix(Image(1),matSize(1),matSize(2));
- g=matrix(Image(2),matSize(1),matSize(2));
- b=matrix(Image(3),matSize(1),matSize(2));
- z(:,:,1)=uint8(r); //Since Matplot is not working with uint16 and uint32, convert every image to a
- z(:,:,2)=uint8(g); //8 bit palette.
- z(:,:,3)=uint8(b); //Note: this will affect the color depth.
- [NumberOfRows NumberOfColumns NumberOfChannels] = size(z);
- NumberOfPixels = NumberOfRows * NumberOfColumns;
- Sample = z(1);
- //printf("\nType of Sample: ");
- //printf(typeof(Sample)); //DEBUG:
- //printf("\n");
- if type(Sample) == 1 then //type 1 = real/complex matrix of double
- ColorMap = matrix(z, NumberOfPixels, NumberOfChannels);
- disp(ColorMap);
- else
- TypeName = typeof(Sample)
- select TypeName
- case 'uint8'
- MaxGrayValue = 2 ^ 8 - 1;
- //printf("uint8\t%d", MaxGrayValue); //DEBUG:
- case 'uint16'
- MaxGrayValue = 2 ^ 16 - 1;
- //ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
- //printf("uint16\t%d", MaxGrayValue); //DEBUG:
- case 'uint32'
- MaxGrayValue = 2 ^ 32 - 1;
- //ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
- //printf("uint32\t%d", MaxGrayValue); //DEBUG:
- end;
- ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) / MaxGrayValue;
- printf("\nCreated colormap with MaxGrayValue = %d\n", MaxGrayValue); //DEBUG:
- end;
- Img=z;
- //Grayscale
- elseif dimensions==1 then
- matSize = size(Image(1));
- Img=matrix(Image(1),matSize(1),matSize(2));
- Img=Img';
- select typeof(Img)
- case 'uint8'
- MaxGrayValue = MaxUInt8;
- case 'uint16'
- MaxGrayValue = max(Image(:)) ;
- case 'uint32'
- MaxGrayValue = max(Image(:));
- end;
- ColorMap = graycolormap(double(MaxGrayValue + 1)); //changed from MaximumGrayValue
- end;
- show(Img,ColorMap);
- endfunction
Add Comment
Please, Sign In to add comment