Image transactions using serial

Dependencies:   mbed

Fork of 06_frdm_serial by hobbielektronika

Committer:
ashutoshns
Date:
Thu Apr 19 11:55:29 2018 +0000
Revision:
1:f72c50b1b93d
Parent:
0:e4d31a61ad72
Image transactions using serial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icserny 0:e4d31a61ad72 1 /** 06_frdm_serial
icserny 0:e4d31a61ad72 2 * Serial demo program for the FRDM-KL25Z board
icserny 0:e4d31a61ad72 3 * Select UART0 for communication via OpenSDA's USB-UART converter
icserny 0:e4d31a61ad72 4 * Default spedd and format are: 9600 bps, 8-bit, no parity, 1 stop bit
icserny 0:e4d31a61ad72 5 */
icserny 0:e4d31a61ad72 6
icserny 0:e4d31a61ad72 7 #include "mbed.h"
icserny 0:e4d31a61ad72 8
icserny 0:e4d31a61ad72 9 Serial pc(USBTX,USBRX); //UART0 via OpenSDA
icserny 0:e4d31a61ad72 10
ashutoshns 1:f72c50b1b93d 11
ashutoshns 1:f72c50b1b93d 12
ashutoshns 1:f72c50b1b93d 13 int ** sobel(int **c,int h,int w)
ashutoshns 1:f72c50b1b93d 14 {
ashutoshns 1:f72c50b1b93d 15 int **image = (int**)malloc(sizeof(int*)*(h-2));
ashutoshns 1:f72c50b1b93d 16 for( int i=0;i<h;i++)
ashutoshns 1:f72c50b1b93d 17 {
ashutoshns 1:f72c50b1b93d 18 image[i]=(int*)malloc(sizeof(int)*(w-2));
ashutoshns 1:f72c50b1b93d 19 }
ashutoshns 1:f72c50b1b93d 20
ashutoshns 1:f72c50b1b93d 21 int x[3][3]={{1,0,-1},{2,0,-2},{1,0,-1}};
ashutoshns 1:f72c50b1b93d 22 int y[3][3]={{1,2,1},{0,0,0},{-1,-2,-1}};
ashutoshns 1:f72c50b1b93d 23
ashutoshns 1:f72c50b1b93d 24 for (int i=1;i<h-1;++i){
ashutoshns 1:f72c50b1b93d 25 for (int j=1; j<w-1; ++j){
ashutoshns 1:f72c50b1b93d 26 for(int k=0;k<3;++k){
ashutoshns 1:f72c50b1b93d 27 for(int l=0;l<3;++l){
ashutoshns 1:f72c50b1b93d 28 image[i-1][j-1] += x[k][l]*c[i-1+k][j-1+l];
ashutoshns 1:f72c50b1b93d 29 }
ashutoshns 1:f72c50b1b93d 30 image[i-1][j-1]=abs(image[i-1][j-1])/8;
ashutoshns 1:f72c50b1b93d 31 }
ashutoshns 1:f72c50b1b93d 32 }
ashutoshns 1:f72c50b1b93d 33 }
ashutoshns 1:f72c50b1b93d 34 return image;
ashutoshns 1:f72c50b1b93d 35 }
ashutoshns 1:f72c50b1b93d 36
icserny 0:e4d31a61ad72 37 int main()
icserny 0:e4d31a61ad72 38 {
ashutoshns 1:f72c50b1b93d 39 int width = 64; int height = 64;
ashutoshns 1:f72c50b1b93d 40 int **image = (int**)malloc(sizeof(int*)*height);
ashutoshns 1:f72c50b1b93d 41 for( int i=0;i<height;i++)
ashutoshns 1:f72c50b1b93d 42 {
ashutoshns 1:f72c50b1b93d 43 image[i]=(int*)malloc(sizeof(int)*width);
icserny 0:e4d31a61ad72 44 }
ashutoshns 1:f72c50b1b93d 45
ashutoshns 1:f72c50b1b93d 46 /*Write headers*/
ashutoshns 1:f72c50b1b93d 47 int i;
ashutoshns 1:f72c50b1b93d 48 for(i=0;i<4096;i++){
ashutoshns 1:f72c50b1b93d 49 image[i/64][i%64]= pc.getc();
ashutoshns 1:f72c50b1b93d 50 }
ashutoshns 1:f72c50b1b93d 51
ashutoshns 1:f72c50b1b93d 52 int **c1= sobel(c,height,width);
ashutoshns 1:f72c50b1b93d 53
icserny 0:e4d31a61ad72 54 }
ashutoshns 1:f72c50b1b93d 55