diff options
Diffstat (limited to 'SD-VBS/common/matlab/readImage.m')
| -rw-r--r-- | SD-VBS/common/matlab/readImage.m | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/SD-VBS/common/matlab/readImage.m b/SD-VBS/common/matlab/readImage.m new file mode 100644 index 0000000..c70222d --- /dev/null +++ b/SD-VBS/common/matlab/readImage.m | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | function srcImage = readImage(pathName) | ||
| 2 | |||
| 3 | %Reading BMP image | ||
| 4 | input = fopen(pathName,'r'); | ||
| 5 | %start of header information | ||
| 6 | signature = fread(input, 2, 'uchar'); | ||
| 7 | file_size = fread(input, 1, 'uint32'); | ||
| 8 | reserved1 = fread(input, 1, 'uint16'); | ||
| 9 | reserved2 = fread(input, 1, 'uint16'); | ||
| 10 | loc_of_bitmap = fread(input, 1, 'uint32'); | ||
| 11 | |||
| 12 | size_of_infoheader = fread(input, 1, 'uint32'); | ||
| 13 | width = fread(input, 1, 'uint32'); | ||
| 14 | height = fread(input, 1, 'uint32'); | ||
| 15 | number_of_planes = fread(input, 1, 'uint16'); | ||
| 16 | bits_per_pixel = fread(input, 1, 'uint16'); | ||
| 17 | compression_method = fread(input, 1, 'uint32'); | ||
| 18 | bytes_of_bitmap = fread(input, 1, 'uint32'); | ||
| 19 | |||
| 20 | hori_reso = fread(input, 1, 'uint32'); | ||
| 21 | vert_reso = fread(input, 1, 'uint32'); | ||
| 22 | no_of_colors = fread(input, 1, 'uint32'); | ||
| 23 | no_of_imp_colors = fread(input, 1, 'uint32'); | ||
| 24 | |||
| 25 | %end of header information | ||
| 26 | |||
| 27 | srcImage = zeros(height, width); | ||
| 28 | |||
| 29 | % Conditions to check whether the BMP is interleaved and handling few exceptions | ||
| 30 | if (height <= 0 || width <= 0 || signature(1) ~= 'B' || signature(2) ~= 'M' || ( bits_per_pixel ==16)) | ||
| 31 | disp('Error in file format'); | ||
| 32 | srcImage = 0; | ||
| 33 | end | ||
| 34 | |||
| 35 | status = fseek(input,loc_of_bitmap,-1); | ||
| 36 | |||
| 37 | nI = 0; | ||
| 38 | nJ = 0; | ||
| 39 | |||
| 40 | if(bits_per_pixel == 24) | ||
| 41 | for nI=height:-1:1 | ||
| 42 | for nJ=1:width | ||
| 43 | tempb = fread(input, 1,'uchar'); | ||
| 44 | tempg = fread(input, 1,'uchar'); | ||
| 45 | tempr = fread(input, 1,'uchar'); | ||
| 46 | srcImage(nI,nJ) = uint8((tempb + 6*tempg + 3*tempr)/10); | ||
| 47 | srcImage(nI,nJ) = uint8(tempg); | ||
| 48 | end | ||
| 49 | end | ||
| 50 | else | ||
| 51 | for nI=height:-1:1 | ||
| 52 | for nJ=1:width | ||
| 53 | tempg = fread(input, 1,'uchar'); | ||
| 54 | srcImage(nI,nJ) = tempg; | ||
| 55 | end | ||
| 56 | end | ||
| 57 | end | ||
| 58 | |||
| 59 | fclose(input); | ||
| 60 | end | ||
