Sharpen filter of bmp image
-
need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?
#include
#include
#include
#include
#includeusing namespace std;
//BMP header
typedef struct tagBITMAPFILEHEADER {
unsigned short bfType;
unsigned int bfSize;
short bfReserved1;
short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
//BMP header
typedef struct tagBITMAPINFOHEADER {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXpelsPerMeter;
int biYpelsPerMeter;
unsigned int biClrUses;
unsigned int biClrImportant;
} BITMAPINFOHEADER;int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);int main()
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
string str = "bitmap.bmp";
const char * nazwa_pliku = str.c_str();
ifstream ifs(nazwa_pliku, ios::binary) ;
if( !ifs.is_open() )
{
cout << "\nBlad otwarcia pliku";
return 0;
}
ofstream ofs("out.bmp", ios::binary);int kursor = odczytajBFH(ifs, bfh);
kursor = odczytajBIH(ifs, bih, kursor);
zapiszBFH(ofs, bfh);
zapiszBIH(ofs, bih);
unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
int szerokosc = bih.biWidth;
int wysokosc = bih.biHeight;u
-
need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?
#include
#include
#include
#include
#includeusing namespace std;
//BMP header
typedef struct tagBITMAPFILEHEADER {
unsigned short bfType;
unsigned int bfSize;
short bfReserved1;
short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
//BMP header
typedef struct tagBITMAPINFOHEADER {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXpelsPerMeter;
int biYpelsPerMeter;
unsigned int biClrUses;
unsigned int biClrImportant;
} BITMAPINFOHEADER;int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);int main()
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
string str = "bitmap.bmp";
const char * nazwa_pliku = str.c_str();
ifstream ifs(nazwa_pliku, ios::binary) ;
if( !ifs.is_open() )
{
cout << "\nBlad otwarcia pliku";
return 0;
}
ofstream ofs("out.bmp", ios::binary);int kursor = odczytajBFH(ifs, bfh);
kursor = odczytajBIH(ifs, bih, kursor);
zapiszBFH(ofs, bfh);
zapiszBIH(ofs, bih);
unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
int szerokosc = bih.biWidth;
int wysokosc = bih.biHeight;u
I don't know Polish so that it is really hard to retrace the code. But you missed some points:
- There are two versions of info headers with different sizes which can be identified using the
biSize
member:BITMAPINFOHEADER
andBITMAPV5HEADER
- When
biCompression
isBI_BITFIELDS
, these bitfields are stored after the info header. - Your code supports only 24-bit RGB bitmaps. So you should check if the file is in that format (
biBitCount
== 24).
You can read the pixel data from file offset
bfOffBits
with sizebiSizeImage
which includes the padding bytes. But your code starts reading after the info header which is the location of the bitfields table or still within aBITMAPV5HEADER
. - There are two versions of info headers with different sizes which can be identified using the