diff options
Diffstat (limited to 'SD-VBS/common/matlab/write_image8u_bmp.m')
-rwxr-xr-x | SD-VBS/common/matlab/write_image8u_bmp.m | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/SD-VBS/common/matlab/write_image8u_bmp.m b/SD-VBS/common/matlab/write_image8u_bmp.m deleted file mode 100755 index 71b48ef..0000000 --- a/SD-VBS/common/matlab/write_image8u_bmp.m +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | function image = write_image8u_bmp(inpImage, pathName) % this is matlab's sequence, removed width, height since they can be inferred from image | ||
2 | |||
3 | BYTES_PER_PIXEL = 3; | ||
4 | |||
5 | fid = fopen (pathName,'w'); %FILE *input; | ||
6 | % //check for the input FILE pointer | ||
7 | if(fid == 0) | ||
8 | disp('File pointer error'); | ||
9 | else | ||
10 | height = size(inpImage,1); | ||
11 | width=size(inpImage,2); | ||
12 | signature(1) = 'B'; | ||
13 | signature(2) = 'M'; | ||
14 | |||
15 | reserved1 = 0; | ||
16 | reserved2 = 0; | ||
17 | file_size = (height*width*BYTES_PER_PIXEL)+54; | ||
18 | offset=54; | ||
19 | size_of_infoheader=40; | ||
20 | number_of_planes=1; | ||
21 | bits_per_pixel= 8*BYTES_PER_PIXEL ; | ||
22 | compression_method=0; | ||
23 | hori_reso=2835; | ||
24 | vert_reso=2835; | ||
25 | no_of_colors=0; | ||
26 | no_of_imp_colors=0; | ||
27 | |||
28 | % start of header information | ||
29 | fwrite(fid,signature(1),'char'); | ||
30 | fwrite(fid,signature(2),'char'); | ||
31 | fwrite(fid,file_size,'int'); | ||
32 | fwrite(fid,reserved1,'short'); | ||
33 | fwrite(fid,reserved2,'short'); | ||
34 | fwrite(fid,offset,'int'); | ||
35 | fwrite(fid,size_of_infoheader,'int'); | ||
36 | fwrite(fid,width,'int'); | ||
37 | fwrite(fid,height,'int'); | ||
38 | fwrite(fid,number_of_planes,'short'); | ||
39 | fwrite(fid,bits_per_pixel,'short'); | ||
40 | fwrite(fid,compression_method,'int'); | ||
41 | |||
42 | bytes_of_bitmap=width*height*BYTES_PER_PIXEL; | ||
43 | |||
44 | fwrite(fid,bytes_of_bitmap,'int'); | ||
45 | fwrite(fid,hori_reso,'int'); | ||
46 | fwrite(fid,vert_reso,'int'); | ||
47 | fwrite(fid,no_of_colors,'int'); | ||
48 | fwrite(fid,no_of_imp_colors,'int'); | ||
49 | |||
50 | % Conditions to check whether the BMP is gray scaled and handling few exceptions | ||
51 | |||
52 | if (width <= 0 || height <= 0 || signature(1) ~= 'B' || signature(2) ~= 'M') | ||
53 | return; | ||
54 | end | ||
55 | |||
56 | % total size of pixels | ||
57 | % pixSize=srcImage->height * srcImage->width * NO_OF_BYTE_PER_PIXEL; //*3 is done as it is a 3 channel image | ||
58 | %reverse the image back | ||
59 | |||
60 | for nI=1:height | ||
61 | count = 0; | ||
62 | for nJ=1:width | ||
63 | temp = inpImage((height - nI+1),nJ,3); | ||
64 | fwrite(fid,temp,'char'); | ||
65 | temp = inpImage((height - nI+1),nJ,2); | ||
66 | fwrite(fid,temp,'char'); | ||
67 | temp = inpImage((height - nI+1),nJ,1); | ||
68 | fwrite(fid,temp,'char'); | ||
69 | |||
70 | end | ||
71 | pad = 4 - (width*BYTES_PER_PIXEL - (4*floor(width*BYTES_PER_PIXEL/4))); %bitmap multiple-of-4 requirement | ||
72 | if pad ~= 0 | ||
73 | temp=0; | ||
74 | for cnt = 1:pad | ||
75 | fwrite(fid,temp,'char'); | ||
76 | % fwrite(fid,temp,'char'); | ||
77 | % fwrite(fid,temp,'char'); | ||
78 | end | ||
79 | end | ||
80 | end | ||
81 | |||
82 | outImage = imread(pathName); | ||
83 | imshow(outImage); | ||
84 | fclose(fid); | ||
85 | |||
86 | end | ||
87 | |||
88 | \ No newline at end of file | ||