void encode(string infile, string outfile, string payload) { BMP input; if(!input.ReadFromFile(infile.c_str())) { cout << "The Bitmap doesn\'t exist!" << endl; return; } int msglength = payload.length() * 2; if(msglength > input.TellWidth() * input.TellHeight()) { cout << "That message is too large for that image! (" << msglength << " as opposed to " << input.TellWidth() * input.TellHeight() << "; " << input.TellWidth() << " * " << input.TellHeight() << ")"<<endl; return; } stringstream msglength_ss; msglength_ss << setfill('0') << setw(8) << hex << msglength; string msglength_str = msglength_ss.str(); uchar msgLength_split[8]; for(uint i = 0; i < msglength_str.length(); i++) { msgLength_split[i] = (uchar)single_char_to_int(msglength_str[i]); } char* payload_split = new char[payload.length() * 2]; for(uint i = 0; i < payload.length() * 2 - 1; i+=2) { payload_split[i] = payload[i / 2] >> 4; payload_split[i + 1] = payload[i/ 2] & 0x0F; } RGBApixel pix; for(int x = 0; x < 8; x++) { pix = input.GetPixel(x, 0); pix.Blue &= 0xF0; pix.Blue += msgLength_split[x]; input.SetPixel(x, 0, pix); } for(int y = 0; y < input.TellHeight(); y++) { for(int x = 0; x < input.TellWidth(); x++) { if(y == 0 && x < 8) continue; pix = input.GetPixel(x, y); if(payload.length() * 2 > (uint)input.TellWidth() * y + x - 8) { pix.Blue &= 0xF0; pix.Blue += payload_split[input.TellWidth() * y + x - 8]; } input.SetPixel(x, y, pix); } } fclose(fopen(outfile.c_str(),"w")); input.WriteToFile(outfile.c_str()); delete[] payload_split; }
int main( int argc, char *argv[] ) { cout << endl << "Using EasyBMP Version " << _EasyBMP_Version_ << endl << endl << "Copyright (c) by the EasyBMP Project 2005-6" << endl << "WWW: http://easybmp.sourceforge.net" << endl << endl; BMP Text; Text.ReadFromFile("EasyBMPtext.bmp"); BMP Background; Background.ReadFromFile("EasyBMPbackground.bmp"); BMP Output; Output.SetSize( Background.TellWidth() , Background.TellHeight() ); Output.SetBitDepth( 24 ); RangedPixelToPixelCopy( Background, 0, Output.TellWidth() - 1, Output.TellHeight() - 1 , 0, Output, 0, 0 ); RangedPixelToPixelCopyTransparent( Text, 0, 380, 43, 0, Output, 110, 5, *Text(0, 0) ); RangedPixelToPixelCopyTransparent( Text, 0, Text.TellWidth() - 1, Text.TellWidth() - 1, 50, Output, 100, 442, *Text(0, 49) ); Output.SetBitDepth( 32 ); cout << "writing 32bpp ... " << endl; Output.WriteToFile( "EasyBMPoutput32bpp.bmp" ); Output.SetBitDepth( 24 ); cout << "writing 24bpp ... " << endl; Output.WriteToFile( "EasyBMPoutput24bpp.bmp" ); Output.SetBitDepth( 8 ); cout << "writing 8bpp ... " << endl; Output.WriteToFile( "EasyBMPoutput8bpp.bmp" ); Output.SetBitDepth( 4 ); cout << "writing 4bpp ... " << endl; Output.WriteToFile( "EasyBMPoutput4bpp.bmp" ); Output.SetBitDepth( 1 ); cout << "writing 1bpp ... " << endl; Output.WriteToFile( "EasyBMPoutput1bpp.bmp" ); Output.SetBitDepth( 24 ); Rescale( Output, 'p' , 50 ); cout << "writing 24bpp scaled image ..." << endl; Output.WriteToFile( "EasyBMPoutput24bpp_rescaled.bmp" ); return 0; }
int main (){ // initializing variables bool sucess; BMP in; BMP out; int width,height,i,j,new_j,new_i; // Set Classes to contain image sucess=in.ReadFromFile("in.bmp"); //cout<<sucess<<endl; sucess=out.ReadFromFile("in.bmp"); //cout<<sucess<<endl; // Find height and width // starting from 0 not 1 so decrement width=(in.TellWidth()); width--; height=in.TellHeight(); height--; //cout<<in.TellWidth()<<endl; //cout<<in.TellHeight()<<endl; // runs horizontally across the image for (i=0;i<=width;i++){ // runs vertically across image for (j=0;j<=height;j++){ // code for finding pixel to change new_i=width-i; new_j=height-j; // code for changing output image out(new_i,new_j)->Red =in(i,j)->Red; out(new_i,new_j)->Green =in(i,j)->Green; out(new_i,new_j)->Blue =in(i,j)->Blue; } } //cout<<"Exiting For loops"<<endl; // write output image to disk out.WriteToFile("out.bmp"); //cout<<"Finished writing out.bmp"<<endl; return 0; }
void testGridFills() { BMP img; img.ReadFromFile(GRIDTESTIMAGE); RGBApixel px; px.Red = px.Blue = 70; px.Green = 25; animation anim = BFSfillGrid(img, GRIDX, GRIDY, px, GRIDGRIDSPACING, GRIDTOLERANCE, GRIDFRAMEFREQ); anim.write("bfsGridTest.gif"); cout << "\tWrote bfsGridTest.gif" << endl; img.ReadFromFile(GRIDTESTIMAGE); anim = DFSfillGrid(img, GRIDX, GRIDY, px, GRIDGRIDSPACING, GRIDTOLERANCE, GRIDFRAMEFREQ); anim.write("dfsGridTest.gif"); cout << "\tWrote dfsGridTest.gif" << endl; }
void pacmanTests() { cout << "Testing PacMan" << endl; // PAC MAN BFS BMP img; img.ReadFromFile("pacMan.bmp"); rainbowColorPicker BFSfiller(1.0/1000.0); animation pacManBFS = BFSfill(img, img.TellWidth()/2, img.TellHeight()/2, BFSfiller, 8000, INT_MAX); img.WriteToFile("pacManBFS.bmp"); cout << "\tWrote pacManBFS.bmp" << endl; //blueManBFS.write("pacManBFS.gif"); // PAC MAN DFS img.ReadFromFile("pacMan.bmp"); rainbowColorPicker DFSfiller(1.0/1000.0); animation pacManDFS = DFSfill(img, img.TellWidth()/2, img.TellHeight()/2, DFSfiller, 8000, INT_MAX); img.WriteToFile("pacManDFS.bmp"); cout << "\tWrote pacManDFS.bmp" << endl; // Make ANTI image BMP antiImg; antiImg.ReadFromFile("pacMan.bmp"); RGBApixel black; black.Red = black.Green = black.Blue = 0; RGBApixel grey; grey.Red = grey.Green = grey.Blue = 1; BFSfillSolid(antiImg, 10, 10, grey, 8000, INT_MAX); BFSfillSolid(antiImg, antiImg.TellWidth()/2, antiImg.TellHeight()/2, black, 8000, INT_MAX); // ANTI PAC MAN BFS img = antiImg; rainbowColorPicker aBFSfiller(1.0/1000.0); animation aManBFS = BFSfill(img, 20, 20, aBFSfiller, 0, 2000); //img.WriteToFile("antiPacManBFS.bmp"); aManBFS.write("antiPacManBFS.gif"); cout << "\tWrote antiPacManBFS.gif" << endl; // ANTI PAC MAN DFS img = antiImg; rainbowColorPicker aDFSfiller(1.0/1000.0); animation aManDFS = DFSfill(img, 20, 20, aDFSfiller, 0, 2000); //img.WriteToFile("antiPacManDFS.bmp"); aManDFS.write("antiPacManDFS.gif"); cout << "\tWrote antiPacManDFS.gif" << endl; }
// filename is a BMP file CImage::CImage(const char * filename, int colors) { BMP bmp; bmp.ReadFromFile(filename); init(bmp.TellWidth(), bmp.TellHeight(), colors); // convert pixels to float values for (int col = 0; col < m_width; col++) { for (int row = 0; row < m_height; row++) { RGBApixel* pixel = bmp(col, row); // m_color == 1 means grayscale... so all components should be equal // (i.e. Red = Green = Blue) if (m_color == 1) setValue(row, col, 0, (float) pixel->Red); else if (m_color == 3) { setValue(row, col, 0, (float) pixel->Red); setValue(row, col, 1, (float) pixel->Green); setValue(row, col, 2, (float) pixel->Blue); } } } }
unsigned int loadImage(const char * fname) { if ( ! fname ) { return 0; } BMP bmp; if ( ! bmp.ReadFromFile(fname) ) { printf( "not loaded : %s\n",fname ); return 0; } int w = bmp.TellWidth(); int h = bmp.TellHeight(); int d = bmp.TellBitDepth() / 8; RGBApixel* pix = bmp(0,0); char bytes[0x7ffff], *b=bytes; for ( int j=0; j<h; j++ ) { for ( int i=0; i<w; i++ ) { RGBApixel pix = bmp.GetPixel(i, j); *b++ = pix.Red; *b++ = pix.Green; *b++ = pix.Blue; if ( d == 4 ) *b++ = pix.Alpha; } } size_t i = RGL::texCreate( w, h, d, bytes, true );; printf( "created : %d [%d %d %d] %s\n", i, w,h,d,fname ); return i; }
void testSolidFills() { BMP img; img.ReadFromFile(SOLIDTESTIMAGE); RGBApixel px; px.Red = 70; px.Green = 50; px.Blue = 13; animation anim = DFSfillSolid(img, SOLIDX, SOLIDY, px, SOLIDTOLERANCE, SOLIDFRAMEFREQ); anim.write("dfsSolidTest.gif"); cout << "\tWrote dfsSolidTest.gif" << endl; img.ReadFromFile(SOLIDTESTIMAGE); anim = BFSfillSolid(img, SOLIDX, SOLIDY, px, SOLIDTOLERANCE, SOLIDFRAMEFREQ); anim.write("bfsSolidTest.gif"); cout << "\tWrote bfsSolidTest.gif" << endl; }
bool Image::readFromBMPFile(const std::string & inputFileName) { bool success = true; // use BMP object to read image BMP inputImage; success = inputImage.ReadFromFile(inputFileName.c_str() ); if( success ) { // allocate memory for image (deleting old, if exists) m_numRows = inputImage.TellHeight(); m_numCols = inputImage.TellWidth(); if( m_pixels != NULL ) // deallocate old memory { delete [] m_pixels; } m_pixels = new double[m_numRows * m_numCols]; // copy pixels for( int r = 0; r < m_numRows; ++r ) { for( int c = 0; c < m_numCols; ++c ) { RGBApixel pixelVal = inputImage.GetPixel(c, r); double val = (double) pixelVal.Blue + (double) pixelVal.Green + (double) pixelVal.Red; val = (val / 3.0 + 0.5); m_pixels[r * m_numCols + c] = val; } } } return success; }
int main() { BMP srcBMP; srcBMP.ReadFromFile("../../../../input/lena.bmp"); BMP dstBMP(srcBMP); int width =srcBMP.TellWidth(); int height=srcBMP.TellHeight(); int size =width*height; unsigned char* srcData= new unsigned char[width*height]; unsigned char* dstData= new unsigned char[width*height]; BMP2graydata(srcBMP, srcData); //sobel( srcData, dstData, width, height); //------- run sobel on nmc -------------- // Access and loading program to nm-board C_PC_Connector_mc5103 Connector(PROGRAM); if (!Connector.isConnected()){ printf("Connection to mc5103 error!"); return -1; } int handshake= Connector.Sync(0xC0DE0086); if (handshake!=0xC0DE6406){ printf("Handshake with mc5103 error!"); return -1; } int ok; ok=Connector.Sync(width); // Send width to nmc ok=Connector.Sync(height); // Send height to nmc ok=Connector.Sync(0); // Get status of memory allocation from nm if (ok!=0x600DB00F){ printf("Memory allocation error!"); return -1; } unsigned srcAddr=Connector.Sync(0); unsigned dstAddr=Connector.Sync(0); Connector.WriteMemBlock((unsigned*)srcData, srcAddr, size/4); // Send data to NMC Connector.Sync(0); // Barrier sync before call of Sobel filter on NMC //... wait while sobel is runing on board unsigned t=Connector.Sync(0); // Barrier sync. Wait until Sobel filter is finished Connector.ReadMemBlock ((unsigned*)dstData, dstAddr, size/4); // Recieve result data from NMC //---------------------- graydata2BMP(dstData, dstBMP); dstBMP.WriteToFile("dst.bmp"); delete srcData; delete dstData; return 0; }
static cell AMX_NATIVE_CALL n_GetImageBAtPos( AMX* amx, cell* params ){ amx_StrParam(amx,params[1],tmp); BMP Image; Image.ReadFromFile(tmp); posx = params[2]; posy = params[3]; return Image(posx,posy)->Blue; }
void testGradientFills() { BMP img; img.ReadFromFile(GRADIENTTESTIMAGE); RGBApixel px; px.Red = px.Blue = 0; px.Green = 25; RGBApixel px2; px2.Red = px2.Blue = 200; px2.Green = 25; animation anim = BFSfillGradient(img, GRADIENTX, GRADIENTY, px, px2, GRADIENTRADIUS, GRADIENTTOLERANCE, GRADIENTFRAMEFREQ); anim.write("bfsGradientTest.gif"); cout << "\tWrote bfsGradientTest.gif" << endl; img.ReadFromFile(GRADIENTTESTIMAGE); anim = DFSfillGradient(img, GRADIENTX, GRADIENTY, px, px2, GRADIENTRADIUS, GRADIENTTOLERANCE, GRADIENTFRAMEFREQ); anim.write("dfsGradientTest.gif"); cout << "\tWrote dfsGradientTest.gif" << endl; }
int main(int argc, char * argv[]) { if (argc < 3) { std::cerr << "Usage: " << argv[0] << " <font name> <font image>...\n"; return 1; } // Average symbol information std::map<char, OCR::Font::Symbol> average; // Image BMP img; // Load a non-existent font OCR::Font bogus("BOGUS"); // Open file for output std::string outFileName = argv[1]; outFileName = "font/" + outFileName + ".font"; std::ofstream outFile(outFileName.c_str()); // Load each line and read its statistics for (int fileNum = 2; fileNum < argc; ++fileNum) { // Create line img.ReadFromFile(argv[fileNum]); OCR::Line line(img, bogus); // Create vector for symbol info std::vector<OCR::Font::Symbol> symbols; symbols.reserve(ALPHABET.size()); // Do the reading line.Read(&symbols); // Loop through and add to the "average" std::vector<OCR::Font::Symbol>::iterator itr = symbols.begin(); for (unsigned charIndex = 0; itr != symbols.end() && charIndex < ALPHABET .size(); ++itr, ++charIndex) { average[ALPHABET[charIndex]] += *itr; } } for (std::map<char, OCR::Font::Symbol>::iterator itr = average.begin(); itr != average.end(); ++itr) { // Divide all statistics by number of lines read itr->second /= (argc - 2); // Print the character and its statistics to the file outFile << itr->first << ' ' << itr->second << std::endl; } outFile.close(); return 0; }
static cell AMX_NATIVE_CALL n_SetImageSize( AMX* amx, cell* params ){ amx_StrParam(amx,params[1],tmp); posx = params[2]; posy = params[3]; BMP Image; Image.ReadFromFile(tmp); Image.CreateStandardColorTable(); Image.SetSize(posx,posy); return Image.WriteToFile(tmp); }
/**Load images by list of files 'file_list' and store them in 'data_set' */ void LoadImages(const TFileList& file_list, TDataSet* data_set) { for (size_t img_idx = 0; img_idx < file_list.size(); ++img_idx) { // Create image BMP* image = new BMP(); // Read image from file image->ReadFromFile(file_list[img_idx].first.c_str()); // Add image and it's label to dataset data_set->push_back(make_pair(image, file_list[img_idx].second)); } }
d_surf * _surf_load_bmp(const char * filename, const char * surfname, REAL minz, REAL maxz, REAL startX, REAL startY, REAL stepX, REAL stepY) { writelog(LOG_MESSAGE, "loading surface from BMP file %s",filename); BMP bmp; if (bmp.ReadFromFile(filename) == false) { writelog(LOG_ERROR,"Error loading surface from bitmap!"); return NULL; } size_t NN = bmp.TellWidth(); size_t MM = bmp.TellHeight(); extvec * coeff = create_extvec( NN*MM, 0, 0, 0); size_t i,j; double gray_color; double alpha; for (j = 0; j < MM; j++) { for (i = 0; i < NN; i++) { gray_color = bmp(i,j)->Red * 0.299 + bmp(i,j)->Green * 0.587 + bmp(i,j)->Blue * 0.114; alpha = bmp(i,j)->Alpha; if (alpha == 255) (*coeff)(i + (MM-1-j)*NN) = undef_value; else { if (minz != maxz) (*coeff)(i + (MM-1-j)*NN) = (maxz-minz)*gray_color/REAL(255) + minz; else (*coeff)(i + (MM-1-j)*NN) = gray_color; } } } d_grid * grd = create_grid(startX, startX + stepX*(NN-1), stepX, startY, startY + stepY*(MM-1), stepY); d_surf * res = create_surf(coeff, grd); if (surfname) res->setName(surfname); else { char * name = get_name(filename); res->setName(name); sstuff_free_char(name); } return res; };
void setup(string const & filename, List<RGBApixel> & pixelList, int & width, int & height) { BMP imgIn; imgIn.ReadFromFile(filename.c_str()); width = imgIn.TellWidth(); height = imgIn.TellHeight(); // fill list with pixels pixelList.clear(); for (int y = 0; y < height; y++) for(int x = 0; x < width; x++) pixelList.insertAfter(*imgIn(x,y)); }
int main(void) { BMP TextImage; TextImage.ReadFromFile("text.bmp"); toBlackAndWhite(TextImage); int symbolCount = 0, lineCount = 0; countAndColor(TextImage, symbolCount, lineCount); TextImage.WriteToFile("output.bmp"); std::cout << "symbols: " << symbolCount << std::endl; std::cout << "lines: " << lineCount << std::endl; }
void SetPaletteBMPImg( const std::vector<gimg::colorRGB24> & srcpal, const std::string & filepath ) { BMP input; uint32_t nbcolstocopy = srcpal.size(); input.ReadFromFile( filepath.c_str() ); //Copy input img into output img BMP output(input); //Sanity check + for removing issues with signed/unsigned mismatch const unsigned int nbColorsOut = static_cast<unsigned int>( ( output.TellNumberOfColors() > 0 )? output.TellNumberOfColors() : 0 ); if( nbColorsOut == 0 ) throw runtime_error("ERROR: BMP image being imported has an invalid palette!"); if( nbColorsOut < srcpal.size() ) { nbcolstocopy = nbColorsOut; cerr <<"WARNING: the palette being injected into \"" <<filepath <<"\" is larger than the palette of the image! Palette has " <<srcpal.size() <<" colors, while the image has " <<output.TellNumberOfColors() <<" colors! Only the first" <<output.TellNumberOfColors() <<" colors will be copied!\n"; } else if( nbColorsOut > srcpal.size() ) { nbcolstocopy = srcpal.size(); cerr <<"WARNING: the palette being injected into " <<filepath <<" is smaller than the palette of the image! Only " <<srcpal.size() <<" colors will be written to the image!\n"; } //reset colors to 0 for( unsigned int i = 0; i < nbColorsOut; ++i ) output.SetColor( i, RGBApixel() ); //Copy colors for( unsigned int i = 0; i < nbcolstocopy; ++i ) { RGBApixel acolor; acolor.Red = srcpal[i].red; acolor.Green = srcpal[i].green; acolor.Blue = srcpal[i].blue; acolor.Alpha = 255; //Always opaque output.SetColor( i, acolor ); } output.WriteToFile(filepath.c_str()); }
string decode(string infile) { BMP input; if(!input.ReadFromFile(infile.c_str())) { cout << "The input file didn't exist!" << endl; return ""; } stringstream ret; int count = 0; char currentChar; RGBApixel pix; int msgLength = 0; stringstream msglength_ss; for(int x = 0; x < 8; x++) { pix = input.GetPixel(x, 0); msglength_ss << hex << (ushort)(pix.Blue & 0x0F); } msgLength = strtol(msglength_ss.str().c_str(), NULL, 16); for(int y = 0; y < input.TellHeight(); y++) { for(int x = 0; x < input.TellWidth(); x++) { if(input.TellWidth() * y + x - 8 > msgLength) goto end; if(y == 0 && x < 8) continue; pix = input.GetPixel(x, y); if(count % 2 == 0) { // Begin new Char currentChar = pix.Blue & 0x0F; } else { // Add to current char currentChar <<= 4; currentChar += pix.Blue & 0x0F; ret << currentChar; } count++; } } end: return ret.str(); }
int importImg(char* filename){ BMP InputIMG; cout << "Starting BMP final code" << endl; cout << "Open File: " << filename << endl; if(!InputIMG.ReadFromFile(filename)){ cout << "Invalid File Name..." << endl; return EXIT_FAILURE; } printFileInfo(InputIMG); COLUMNS = InputIMG.TellWidth(); // num cols ROWS = InputIMG.TellHeight(); // num rows DEPTH = InputIMG.TellBitDepth(); //allocate Memory imageArray = new int *[COLUMNS] ; // row memory allocation for( int i = 0 ; i < COLUMNS ; i++ ){ // column memory allocation imageArray[i] = new int[ROWS]; } thetas = new float *[COLUMNS]; for(int i = 0; i < COLUMNS; i++) { thetas[i] = new float[ROWS]; } magArray = new int *[COLUMNS]; for(int i=0; i < COLUMNS; i++) { magArray[i] = new int[ROWS]; } int Temp; cout<< "Saving Brightness values" << endl; for( int j=0 ; j < ROWS ; j++) { for( int i=0 ; i < COLUMNS ; i++) { Temp = (int) floor( 0.299*InputIMG(i,j)->Red + 0.587*InputIMG(i,j)->Green + 0.114*InputIMG(i,j)->Blue ); imageArray[i][j] = Temp; } } }
static cell AMX_NATIVE_CALL n_SetPixelRGBA( AMX* amx, cell* params ){ amx_StrParam(amx,params[1],tmp); BMP Image; posx = params[2]; posy = params[3]; Image.ReadFromFile(tmp); RGBApixel value; value.Red = (ebmpBYTE)params[4]; value.Green = (ebmpBYTE)params[5]; value.Blue = (ebmpBYTE)params[6]; value.Alpha = (ebmpBYTE)params[7]; Image.SetBitDepth(24); Image.GetPixel(posx,posy); Image.SetPixel(posx,posy,value); return Image.WriteToFile(tmp); }
Matrix<std::tuple<T, T, T>> load_image(const char *path) { BMP in; if (!in.ReadFromFile(path)) throw string("Error reading file ") + string(path); Matrix<std::tuple<T, T, T>> res(in.TellHeight(), in.TellWidth()); for (uint i = 0; i < res.n_rows; ++i) { for (uint j = 0; j < res.n_cols; ++j) { RGBApixel *p = in(j, i); res(i, j) = make_tuple(T(p->Red), T(p->Green), T(p->Blue)); } } return res; }
int main(int argc, char *argv[]){ //verify input if(!getAndVerifyInput(argc, argv)){ system("pause"); return 0; } //read input file BMP img; img.ReadFromFile("inputImage1.bmp"); readFile(img); //set seed point (can do multiple calls to set multiple seed points) if(fillSphere(250, 250, 10) == 0){ system("pause"); return 0; } initialization(); calculateMu(); //only needed if the Chan Vese speed function is used list<Pixel>::iterator itt; printf("starting main loop\n"); start = std::clock(); for(int i=1; i<iterations; i++){ prepareUpdates(); updateLevelSets(); if(i%100 == 0){ printf("\niteration: %i\n", i); } } duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; printf("\nmain loop finished\n"); printf("\ntime used: %f\n", duration); for(itt = lz.begin(); itt != lz.end(); itt++){ zeroLevelSet[itt->x][itt->y] = 255; } writeFile(img, 1, iterations); writeFile(img, 2, iterations); system("pause"); }
int main (int argc, char* argv[]) { BMP image; image.ReadFromFile("input.bmp"); int width = image.TellWidth(); int height = image.TellHeight(); letterData data[10000]; BMP imageOut; imageOut.SetSize(width, height); Conversion(image, imageOut, data); imageOut.WriteToFile("output.bmp"); return 0; }
QImage fromBMP(QString &file) { QImage errImg; BMP tarBMP; if(!tarBMP.ReadFromFile( file.toLocal8Bit().data() )){ //WriteToLog(QtCriticalMsg, QString("Error: File does not exsist")); return errImg; //Check if empty with errImg.isNull(); } QImage bmpImg(tarBMP.TellWidth(),tarBMP.TellHeight(),QImage::Format_RGB666); for(int x = 0; x < tarBMP.TellWidth(); x++){ for(int y = 0; y < tarBMP.TellHeight(); y++){ RGBApixel pixAt = tarBMP.GetPixel(x,y); bmpImg.setPixel(x,y,qRgb(pixAt.Red, pixAt.Green, pixAt.Blue)); } } return bmpImg; }
void main () { BMP picture; picture.ReadFromFile("a.bmp"); std::vector<std::vector<rect> > r = get_char_rects(picture); std::vector<std::vector<rect> >::iterator it = r.begin(); for (; it != r.end(); it++) { std::vector<rect>::iterator itt = (*it).begin(); for (; itt != (*it).end(); itt++) { // std::cout << "((" << itt->first.first << ", " << itt->first.second << "), (" << itt->second.first << ", " << itt->second.second << "))" << std::endl; std::cout << (double)itt->first.first / picture.TellWidth() << ", " << 1.0 - ((double)itt->first.second / picture.TellHeight()) << ", " << (double)itt->second.first / picture.TellWidth() << ", " << 1.0 - ((double)itt->second.second / picture.TellHeight()) << ", " << std::endl; } } system("PAUSE"); }
//图像转数组 void bmp2array() { int i,j; BMP bmp; int *pdata=NULL; int *phead=NULL; int *buf=NULL; int width; int height; bmp.ReadFromFile("examp_bmp2array.bmp"); width = bmp.TellWidth(); height= bmp.TellHeight(); pdata=(int*)malloc(width*height*sizeof(int)); phead = pdata; for(i=0;i<height;i++) { for(j=0;j<width;j++) {//打印模拟图,空白为'.',黑色为'M' *pdata=bmp(j,i)->Red;//位深1,读Red分量即可 pdata++; } } //save pdata=phead; for(i=0;i<height;i++) { for(j=0;j<width;j++) {//打印至终端 printf("%d,",*pdata); pdata++; } printf("\n"); } printf("bmp2array suc...\n"); getchar(); }
int main() { BMP srcBMP; srcBMP.ReadFromFile("../../../input/lena.bmp"); BMP dstBMP(srcBMP); int width =srcBMP.TellWidth(); int height=srcBMP.TellHeight(); unsigned char* srcData= new unsigned char[width*height]; unsigned char* dstData= new unsigned char[width*height]; BMP2graydata(srcBMP, srcData); sobel( srcData, dstData, width, height); graydata2BMP(dstData, dstBMP); dstBMP.WriteToFile("dst.bmp"); delete srcData; delete dstData; return 0; }
int main(int argc, char* argv[]) { cout << "Enter filename with max 30 characters:" << endl; char s[30]; cin.getline(s, 30); //char* s = std::cin; BMP Image; if (Image.ReadFromFile(s)){ int height = Image.TellHeight(); int width = Image.TellWidth(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { double Temp = 0.30*(Image(x, y)->Red) + 0.59*(Image(x, y)->Green) + 0.11*(Image(x, y)->Blue); Image(x, y)->Red = (Byte)Temp; Image(x, y)->Green = (Byte)Temp; Image(x, y)->Blue = (Byte)Temp; } } Image.SetBitDepth(8); CreateGrayscaleColorTable(Image); char output[30] = "grey_"; strcat(output, s); std::cout << output << std::endl; Image.WriteToFile(output); } std::cin.get(); return 0; }