160 likes | 407 Views
Bitmap files and manipulation using Matlab. The bitmap (.bmp) file. Loading and manipulation in Matlab The bmp header and file structure. Modifications to our structure for colour. 240. 63. Now we need three separate matrices, one for each colour. Each matrix holds
E N D
Bitmap files and manipulation using Matlab. • The bitmap (.bmp) file. • Loading and manipulation in Matlab • The bmp header and file structure.
Modifications to our structure for colour 240 63 Now we need three separate matrices, one for each colour. Each matrix holds values which represent the corresponding colour in the image 240 63 240 63 Our matrix is now Of size 640 x 480 x 3
Loading, saving and showing bitmaps in Matlab • A=imread(‘filename1.bmp’) • B=imread(‘filename2.bmp’) • imwrite(Array,‘filename.bmp’) • image(A) • Change “edit -> axis properties” to “Set axis equal shape” • Note that A is class uint8.
Manipulating the image Rows • Use : operator to select certain rows only, then look at it • Eg newim=[A( 101:200, : , :) ; image(newim) Columns • Use : operator to select certain columns only, then look at it. • Eg newim=[A( :, 251:300 , :) ; image(newim)
Manipulating the image Crop • Use : operator to select certain rows and columns then look at it • Eg newim=[A( 101:200, 251 : 300, :) ; image(newim)
Piecing two images together. • Linewise • newim= [A( start:end, : , :) ; B(start:end,:,:)] Images 1 and 2 must have same number of columns • Columnwise • newim= [A( : , start:end, :) B(:, start:end, :)] Images 1 and 2 must have same number of lines.
Altering the overall brightness and contrast of an image. • If we want a neutral change we must make the same change to all three primaries. • Brightness • An offset operation • Use + or – • Contrast • A scaling operation • Use * or / • Exceeding 255 will cause ‘clipping’. • Numbers less than zero will cause ‘crushing’
Changing Brightness • newim=A-127 image(newim) • We can increase it again newim= A+127 image(newim) • If we increase/decrease values below 0 or above 255 we lose information in the image, try it.
Changing Contrast • Now use multiplication to increase the contrast. newim=A*2 image(newim)
Changing the colour of an image. • Operate (+ - * /) on different colours • Example • Give picture a red lift newim=A; newim(:, :, 1)=newim(:, :, 1)+20; image(newim);
The bitmap format .bmp • Contains the following data structures: • BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; RGBQUAD aColors[]; BYTE aBitmapBits[];
The bitmap format .bmp • BITMAPFILEHEADER
The bitmap format .bmp • BITMAPINFOHEADER
The bitmap format .bmp • BITMAPINFOHEADER
The bitmap format .bmp • RGBQUAD array for colour map (not used for 24 bit colour)
The bitmap format Notes • “biwidth” important for rows and column structure, change it and see. • Bitmap data is “upside down”. • “Length” data is LSB first.