Image conversion to a two-dimensional array deposit DSP6748

Source: Internet
Author: User
Tags radar



This article is original works, reproduced please indicate the source

Welcome to my blog: http://blog.csdn.net/hit2015spring and the http://www.cnblogs.com/xujianqing/


This blog is mainly about how to save a picture into a binary file, directly to dsp Do not consider dsp The data communication with the Image Acquisition module or the host computer makes us more focused on the development of the algorithm and the implementation of the processing function.

This is the work done recently, the main development of radar image processing target detection algorithm. The idea is to first convert the ready-made radar image into an array, and then include it in the program as a header file. Used to validate algorithms and compute speed. DSP Adopt TI Company's 6000 series single-core processors, 6748 . (the background is complete, can be ignored).

Hors d ' oeuvres ---MATLAB size() function imread() function

in matlab , for size function whose return value is:

[ROW,COL] = size (A) ,

For example:

A = [0, 1, 2; 0, 1, 2];size (a)

Ans =

2 3

Here a is a matrix of two rows and three columns

After reading a picture, (this default is grayscale) returns a matrix with the number of rows and columns corresponding to the height and width of the image, respectively.

STR1 = ' C:\Users\yezi\Desktop\dsp processing \ '; str2 = ' 111.bmp '; str3 = strcat (STR1,STR2); image = Imread (STR3);

In matlab read a picture under the specified path,matlab has provided a imread() function, which returns the grayscale value of each pixel of a digital picture, and saves it as a matrix image.

Number of rows--height

Number of columns--width

What is the height width of the picture?

On the picture "right"-"properties"-"More info"

A imread function is also provided in OPENCV , which reads an image and coexists with an object of the Mat class. Also contains an image matrix, the number of row series is the same as matlab .

Save the picture into a one-dimensional array, and then in the DSP to restore it to a two-dimensional matrix, so the number of rows is very important. It is the understanding of this function, solved I in the DSP read the picture when the number of rows, the number of columns confused after the error, first remember it.


DSP6748read the picture related introduction

In the development of DSP6748 image processing algorithm, you can use fopen (),fread () function, in the CCS integrated development environment, directly read the file under the specified path in the host computer, However, this must be done in Debug mode, via a link in the emulator.

In emulation mode, it takes a long time to read an image from the host computer through an emulator. So in order to debug the speed and needs of the algorithm, I convert the image into a header file included in the program, which is also the usual practice.


picture converted to character array form


TIthe conversion tools provided

TI The company provides a small conversion tool, in the c6748_starterware package, the specific path is: .. \C6748_STARTERWARE_1_20_04_01\TOOLS\BMP2C

Specific usage:


  1. Copy the image you want to convert to the tool tools\bmp2c directory under

  2. Under this directory, hold down the shift key, right-click here to open Command window

  3. Enter the command: bmp2c-8 inputname.bmp outputname.c  

  4. Automatically generate character array files outputname.c

Image:

Conversion window:


Converted files:


It seems very convenient to look at, but the good thing is always more grinding, unfortunately this tool is only support for the depth and depth of the picture, and I need to be a 8 -bit image, is a grayscale image into a character array file, So I had to do it myself:


My Conversion Tool


Then the code of matlab I wrote:

Percent read into the grayscale image, into a binary file, that is, a one-dimensional array of clear   clc[rgb,map]=imread (' gray1234.bmp ');% reads the picture that needs to be converted, picture and M file under a path h=rgb;i1=double (H ); [M,n]=size (I1); information12 = ' #ifndef image_h_\n ' information13 = ' #define image_h_\n\n\n\n\n ' Fid=fopen (' image.h ', ' Wt ');   % Create a file in the current directory write Data fprintf (FID,INFORMATION12); fprintf (fid,information13); fprintf (FID, ' const unsigned char image[] = { \ n ');% write array name n=0;for i=1:m   %fprintf (FID, ' {'); for j=1:n                                     % write Data    n=n+1;    fprintf (FID, ' 0x%x ', I1 (i,j));          if (J ~= N) | | (i ~= M);              fprintf (FID, ', ');           End    endfprintf (FID, ' \ n '); endfprintf (FID, '};\n '); fprintf (FID, ' #endif/* image_h_ */'); fclose (FID);

Because MATLAB can support a good variety of image format reading, so as long as the image suffix transformation, the tool can support a variety of formats of the picture!!! But is the conversion of gray-scale, is actually a two-dimensional array, but you can follow the above thinking, slightly modify the code, you can turn out the RGB three-dimensional array.

Code: Click to open link

After converting the header file:

This conversion is complete.

By including the header file in the CCS project, the image can be processed directly.

the main function test code in CCS :

void Main () {int i; int j;for (i = 0; i < height; i++) {for (j = 0; J < width; ++j) {Ba[i][j] = image[i * width + j];}}

BA to re-convert the picture one-dimensional array to a two-dimensional array. Note that height is the number of rows, andwidth is the number of columns


As shown, it is clear that the width and height are divided, and then converting one-dimensional arrays into two-dimensional arrays is not wrong. That's the point of attention I'm talking about at the beginning.

Okay, here's the end of the article! Welcome interested friends to communicate, criticize correct! I hope that my ideas can bring you some inspiration!





Image conversion to a two-dimensional array deposit DSP6748

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.