From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- SD-VBS/common/matlab/readImage.m | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 SD-VBS/common/matlab/readImage.m (limited to 'SD-VBS/common/matlab/readImage.m') 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 @@ +function srcImage = readImage(pathName) + + %Reading BMP image + input = fopen(pathName,'r'); + %start of header information + signature = fread(input, 2, 'uchar'); + file_size = fread(input, 1, 'uint32'); + reserved1 = fread(input, 1, 'uint16'); + reserved2 = fread(input, 1, 'uint16'); + loc_of_bitmap = fread(input, 1, 'uint32'); + + size_of_infoheader = fread(input, 1, 'uint32'); + width = fread(input, 1, 'uint32'); + height = fread(input, 1, 'uint32'); + number_of_planes = fread(input, 1, 'uint16'); + bits_per_pixel = fread(input, 1, 'uint16'); + compression_method = fread(input, 1, 'uint32'); + bytes_of_bitmap = fread(input, 1, 'uint32'); + + hori_reso = fread(input, 1, 'uint32'); + vert_reso = fread(input, 1, 'uint32'); + no_of_colors = fread(input, 1, 'uint32'); + no_of_imp_colors = fread(input, 1, 'uint32'); + + %end of header information + + srcImage = zeros(height, width); + + % Conditions to check whether the BMP is interleaved and handling few exceptions + if (height <= 0 || width <= 0 || signature(1) ~= 'B' || signature(2) ~= 'M' || ( bits_per_pixel ==16)) + disp('Error in file format'); + srcImage = 0; + end + + status = fseek(input,loc_of_bitmap,-1); + + nI = 0; + nJ = 0; + + if(bits_per_pixel == 24) + for nI=height:-1:1 + for nJ=1:width + tempb = fread(input, 1,'uchar'); + tempg = fread(input, 1,'uchar'); + tempr = fread(input, 1,'uchar'); + srcImage(nI,nJ) = uint8((tempb + 6*tempg + 3*tempr)/10); + srcImage(nI,nJ) = uint8(tempg); + end + end + else + for nI=height:-1:1 + for nJ=1:width + tempg = fread(input, 1,'uchar'); + srcImage(nI,nJ) = tempg; + end + end + end + + fclose(input); +end -- cgit v1.2.2