473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help me out plzzz

I have a minor problem with the following code..it reads a .bmp image
and is supposed to produce another .bmp image which is the result of
histogram equalization of the input image...kindly go through it
1st...and the query follows at the end...

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <mem.h>
#include <string.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <math.h>

unsigned char r[360],mini,mode;
unsigned char rgb[256][3],rgb2[256][3],**rgb1;
char *fullname;
char *fname;
int hist[256],tmp=0,sum=0,t;
unsigned int screen_width=320;
unsigned int first_row=0,first_column=0,last_row=0,last_column= 0;
int handle,i,j,rem,color_bits;
long int
file_size,data_offset,size_info_header,width,heigh t,compression,

image_size,xpelspermeter,ypelspermeter,colorsused, k,colorsimpt,p,index,max,min,**sum_hist;
float theta,temp;
void drawdot(int x, int y, int pal_index){
_AX=pal_index;
_CX=x;
_DX=y;
_AH=0x0c;
_BH=0x00;
geninterrupt(0x10);
}

void main(){

gets(fname);
strcpy(fullname,fname);strcat(fullname,".bmp");
handle=_open(fullname,O_RDONLY);if (handle==-1) exit(EXIT_FAILURE);
_read(handle,r,2);if (r[0] !='B' | r[1] !='M') exit(EXIT_FAILURE);
_read(handle,r,
4);file_size=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);_read(handle,r,2);
_read(handle,r,
4);data_offset=r[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
_read(handle,r,
4);size_info_header=r[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
if (size_info_header !=40) exit(EXIT_FAILURE);
_read(handle,r,4);width=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
if (width screen_width) exit(0);
_read(handle,r,4);height=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);if (r[0] != 1) exit(EXIT_FAILURE);
_read(handle,r,2);
color_bits=r[0];
_read(handle,r,4);
compression=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
image_size=r[0]+256*r[1]+256*256*r[2]+256*256*256*r[3];
_read(handle,r,4);
xpelspermeter=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
ypelspermeter=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsused=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsimpt=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];

_AX=0x1201;_BL=0x33;geninterrupt(0x10);//don't add RGB
_AX=0x0013;geninterrupt(0x10);//set mode 13 i.e. 320x200x256

for (i=0;i<256;i++) {
_read(handle,r,4);
rgb[i][0]=r[2]>>2;rgb[i][1]=r[1]>>2;rgb[i][2]=r[0]>>2;
}
rgb1=calloc(height,sizeof(char*));
for(i=0;i<height;i++)
rgb1[i]=calloc(width,sizeof(char));
for (i=0;i<256;i++) {
rgb2[i][0]=i;rgb2[i][1]=i;rgb2[i][2]=i;
}
_ES=FP_SEG(rgb2);_DX=FP_OFF(rgb2);
_BX=0;_CX=0x100; _AX=0x1012;
geninterrupt(0x10);//set DAC from rgb

first_column=(screen_width-width)/2;
last_row=first_row+height-1;last_column=first_column+width-1;
rem=4 - (width % 4);
for (i=0;i<=height-1;i++) {
_read(handle,r,width);

for (j=0;j<=width-1;j++)
{
//drawdot(first_column+j,last_row-i,r[j]);
rgb1[i][j]=(rgb2[r[j]][0]+rgb2[r[j]][1]+rgb2[r[j]][2])/3;

}
if (rem==1) _read(handle,r,1);
else if (rem==2) _read(handle,r,2);
else if (rem==3) _read(handle,r,3);//getch();
}

for(i=0;i<256;i++)
{
hist[i]=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
k=(long int)rgb1[i][j];
hist[k]=hist[k]+1;
}
}

for(i=0;i<256;i++)
{
if(hist[i]!=0)
tmp++;
else continue;
}

sum_hist=(long int **)calloc(tmp,sizeof(long int*));
for(i=0;i<tmp;i++)
sum_hist[i]=(long int *)calloc(2,sizeof(long int));
for(i=0;i<256;i++)
{
if(hist[i]!=0)
{
sum_hist[sum][0]=(long int)i;
sum_hist[sum][1]=(long int)hist[i];
sum++;
}
else continue;
}
for(i=1;i<tmp;i++)
sum_hist[i][1]+=sum_hist[i-1][1];
min=sum_hist[0][1];
max=sum_hist[0][1];
for(i=1;i<tmp;i++)
{
if(min>sum_hist[i][1])
min=sum_hist[i][1];
else continue;
}
for(i=1;i<tmp;i++)
{
if(max<sum_hist[i][1])
max=sum_hist[i][1];
else continue;
}

p=((height*width)-min);

for(i=0;i<height;i++)
{
for(j=0;j<widthj++)
{
t=(int)rgb1[i][j];
for(i=0;i<tmp;i++)
{
if(sum_hist[i][0]==t)
index=sum_hist[i][1];
}
index=index-min;
rgb1[i][j]=abs(index*255/p);
//drawdot(first_column+j,last_row-i,rgb1[i][j]);
}
}
/*for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
drawdot(first_column+j,last_row-i,rgb1[i][j]);
}*/

_close(handle);
getch();
_AX=0x1201;_BL=0x33;geninterrupt(0x10);//don't add RGB
_AX=0x0003;geninterrupt(0x10);//set mode 3 i.e. 16-color text

}

tillthis following segment..
for(i=0;i<height;i++)
{
for(j=0;j<widthj++)
{
t=(int)rgb1[i][j];
for(i=0;i<tmp;i++)
{
if(sum_hist[i][0]==t)
index=sum_hist[i][1];
}
index=index-min;
rgb1[i][j]=abs(index*255/p);
//drawdot(first_column+j,last_row-i,rgb1[i][j]);
}
everything is going well...but nothing is being done as soon as the
for loops end...therefore I cant print the output image..What is the
remedy???
Sep 13 '08 #1
2 1382
biplab <ge*******@gmail.comwrites:
I have a minor problem with the following code..it reads a .bmp image
and is supposed to produce another .bmp image which is the result of
histogram equalization of the input image...kindly go through it
1st...and the query follows at the end...
<snip>
char *fname;
<snip>
void main(){

gets(fname);
This looks familiar. Did you not understand the advice you got last
time? Use int main(void), don't use gets, and ensure that when you
read in data there is somewhere for it to go (fname is NULL). There
were other comments but, I'd start here if I were you.

--
Ben.
Sep 13 '08 #2
On Sat, 13 Sep 2008 11:03:25 -0700 (PDT), biplab <ge*******@gmail.com>
wrote:
>I have a minor problem with the following code..it reads a .bmp image
and is supposed to produce another .bmp image which is the result of
histogram equalization of the input image...kindly go through it
1st...and the query follows at the end...
This code has all the same problems as the similar code you posted on
10 September in the "Reading .bmp file in C" thread. Until you apply
the corrections suggested in that thread there is no point in
repeating them here.

--
Remove del for email
Sep 14 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: aj | last post by:
plzz help me to add How a Blank row in a datagrid without using dataset or any other. plzzz help me
31
by: tamara omar | last post by:
i want to build a java program that can search for words in a text and can replace word by another one and the interface will be diveded as 1-a large space for a text that is chosen by user 2-a...
1
by: itsjyotika | last post by:
Hello Everyone, I need to read data from a CVS file(i created it from micosoft excel) and then need to match it with the one of the date from the command line.If the date is there then it should say...
1
by: gonu | last post by:
i have .net installation problem i start the actual install with disk-1 and everything goes fine until a DLL named vdt70vcs.dll is being used/installed A message box pops up asking me to insert...
0
by: gruntday | last post by:
hey guys can any one help me or give me any detailed idea on how to do this: i want to make an application with visual basic 6 to open an existing .ppt file and edit the values of each msgraph in...
2
by: zaheer181 | last post by:
Hai everybody, Iam assigned a task of implementing fuzzy c means algorithm in matlab to C language using graphics.h and my question is can we implement the same intensity of graphics in matlab...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
1
by: ask84 | last post by:
PLzzz guyz help me wid this payroll, there's some place where I'm making a mistake and unable to compile this program: WHYYYYY!! I'm so frustrated It's from Intro to Programming C++ using Dev-C++...
4
by: bsonline | last post by:
I hv a datetime format like '24/01/2008 15:56:01' . Now I have to select dates from a date range, but input datetime format like 24/1/2008 15:56:01'. I hv written the query like : "select...
4
by: mittalkratika817 | last post by:
i m a student of btech 1st year.i need a c program including graphics n files.i need it in within 1hr...or as soon as poosibl.plzzz help me.m nt in mona cls.thr shud b some animatn.it shud nt b...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.