Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 109,297 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,221 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Reading images, trying to understand code provided from a book

 
Reply to this topicStart new topic

Reading images, trying to understand code provided from a book

hamimah
post 6 Aug, 2008 - 12:12 AM
Post #1


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

Dear all....

I am very new to C programming and I really need some guidance. I am involved in an image processing research and it requires coding in C++ to process the images.

Well, as I mentioned before, I really have no idea on C++, so I end up purchasing varous kind of c++ books (C++ for dummies, tutorials, basics in image processing using C++, and so on...)

well, my very basic question is:

where do you store the image that is required to be processed? the code that is given in the book (basic image processing using C++) is as below:

CODE

read_image_array(file_name, array)
char *file_name;
short **array;
{
int ok = 0;
if (is_a_tiff(file_name))
{ read_tiff_image(file_name, array);
ok=1;
}
}


do i change the file_name to the name of the image? how does it know where to search for the image? ex:local disk C or D?

I am very very lost. Please help.
thanks in advance.

hamimah
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 6 Aug, 2008 - 12:27 AM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,939



Thanked 27 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


The syntax for this is incorrect.

CODE

read_image_array(file_name, array)

I am guessing that read_image_array is a function that takes two arguments. It should end with a semi-colon.

CODE

char *file_name;
short **array;

These are ok, but what does the following curly bracket open? Is this the entrance to the program? Is this int main, or is this the code for read_image_array?

CODE

{
int ok = 0;
if (is_a_tiff(file_name))
{ read_tiff_image(file_name, array);
ok=1;
}
}

& also, you've set ok to a value of zero, & that will get changed to a 1 the function if is_a_tiff returns true. When does the variable ok get used?

I'm not sure how to answer your question "where they get stored", as I have never really used C/C++ to work with images. I would think file_name is going to be a file pointer, & the file would be opened with fopen. But that's just taking a wild guess. What book is this?
User is offlineProfile CardPM

Go to the top of the page

hamimah
post 6 Aug, 2008 - 01:05 AM
Post #3


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

Dear no2pencil,

The title of the book is Image Processing in C: Analyzing and Enhancing Digital Images.

the code actually read an image. the full code from the book is as follows:

CODE

/******************************
*
*  read_image_array(...
*
*  This routine reads the image data
*  from either a tiff or bmp image.
*
*******************************/

read_image_array*file_name, array(
  char *file_name;
  short **array;

{
  int ok=0;

  if(is_a_tiff(file_name))
  {
     read_tiff_image(file_name,array);
     ok=1;
  }

  if(is_a_bmp(ile_name))
  {
     read_bmp_image(file_name, array);
     ok=1;
  }

  if(ok==0)
  {
    printf("\nERROR could not read file %s", file_name);
    exit(1);
  }
} /* ends read_image_array*/


It does says here that it reads from a tiff or bmp file format, but does not tell where does it take it from, local disk C: or D: or from a pendrive?

Where actually do I have to place the image?


Thanks for the fast reply.

Many thanks in advance.

Hamimah
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 6 Aug, 2008 - 04:54 AM
Post #4


T3H R0XX0R!

Group Icon
Joined: 6 Feb, 2008
Posts: 2,591



Thanked 51 times

Dream Kudos: 1450

Expert In: (X)HTML, CSS, Batch Scripting, C, C++

My Contributions


You have couple of syntactical errors.

Check this out:
cpp
/******************************
*
* read_image_array(...
*
* This routine reads the image data
* from either a tiff or bmp image.
*
*******************************/

void read_image_array( char *file_name, short **array)
{
int ok=0;

if(is_a_tiff(file_name))
{
read_tiff_image(file_name,array);
ok=1;
}

if(is_a_bmp(ile_name))
{
read_bmp_image(file_name, array);
ok=1;
}

if(ok==0)
{
printf("\nERROR could not read file %s", file_name);
exit(1);
}
} /* ends read_image_array*/


More specifically, the problem is on your parameters in your functions. Here:
void read_image_array( char *file_name, short **array )
Basically, you need to do the following:
  • Specify a return type
  • Give it a name
  • Specify the parameters within the brackets

Hope this helps smile.gif
User is online!Profile CardPM

Go to the top of the page

hamimah
post 6 Aug, 2008 - 07:27 AM
Post #5


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

Dear Gabehabe,

Thank you for the guidance.

It helped alot. I dont want to be stubborn or anything, but partial of my question still isnt answered. Can anybody help me.

My question is:

For example, if I was to use matlab, my files or images that is going to be processed on will have to be within C:/Program Files/Matlab/Work....am I correct?

What if I was to use C++? Where should my files or images be if I wanted to call the image in a subroutine used in the C++ codings? C:/Program Files/............

I never used C++ before so maybe can someone point it out to me.

Many thanks in advance.

Hamimah
User is offlineProfile CardPM

Go to the top of the page

harshakirans
post 6 Aug, 2008 - 07:37 AM
Post #6


D.I.C Head

Group Icon
Joined: 26 Apr, 2006
Posts: 104



Dream Kudos: 150
My Contributions


Hi Hamimah,

In C or C++ the image file can reside in the source directory or you can specify the path to the image as follows

example: if our image named image.bmp is in C:\Hamimah\image.bmp

you can specify your filename as filename="c:\\Hamimah\\image.bmp";


Hope this helps,

Regards,
Harsha
User is offlineProfile CardPM

Go to the top of the page

hamimah
post 6 Aug, 2008 - 07:44 AM
Post #7


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

Dear Harshakirans,

wow...thanks a lot.....that good to know...

thank you all....no2pencil,gabehabe, and harshakirans......

I am on my way to code my first ever C++ codings that does not display "hello World"...

hehehehe...thanks...that really hit the spot..


Hamimah
User is offlineProfile CardPM

Go to the top of the page

kapax
post 6 Aug, 2008 - 10:41 AM
Post #8


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 37



Thanked 1 times
My Contributions


You gotta start from learning the syntax smile.gif
User is offlineProfile CardPM

Go to the top of the page

perfectly.insane
post 6 Aug, 2008 - 03:30 PM
Post #9


D.I.C Addict

Group Icon
Joined: 22 Mar, 2008
Posts: 509



Thanked 38 times
My Contributions


The syntax is not incorrect. It is an old standard called K&R C (as in, before ANSI C). The book you are reading must be rather old, as this is rarely used anymore (or perhaps it was written by older programmers who learned with this standard).

This post has been edited by perfectly.insane: 6 Aug, 2008 - 03:32 PM
User is offlineProfile CardPM

Go to the top of the page

hamimah
post 6 Aug, 2008 - 09:55 PM
Post #10


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

QUOTE(perfectly.insane @ 6 Aug, 2008 - 03:30 PM) *

The syntax is not incorrect. It is an old standard called K&R C (as in, before ANSI C). The book you are reading must be rather old, as this is rarely used anymore (or perhaps it was written by older programmers who learned with this standard).



Owh really? My goodness, that means the book is bad for me....No wonder there are so many used books of this kind and I bought it for $20.90 from a website.

hmmm....I think I better get another book then. Thanks~!!! biggrin.gif tongue.gif
User is offlineProfile CardPM

Go to the top of the page

KYA
post 7 Aug, 2008 - 07:38 AM
Post #11


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 2,912



Thanked 22 times

Dream Kudos: 1150
My Contributions


a book with at least a copyright of 2000 or later should be OK (maybe even 1997 which was when the last version of C++ was "released")
User is online!Profile CardPM

Go to the top of the page

hamimah
post 7 Aug, 2008 - 07:29 PM
Post #12


New D.I.C Head

*
Joined: 13 May, 2008
Posts: 9

the book' copyright is 1998....

have any suggestions on a good book on digital image processing using C++? I found one using matlab but havent bump into any that is using C++. unsure.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 9/6/08 09:46AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month