I have a problem at hand. It is to generate a C code - i need to do the following, i will capture an image, then i have to this image into an array using C on which i can do some image processing. How do i go about it? If someone could give me some codes showing how to procedd it would be great....

thank u
j

for starters u can get the image (100x100 pixels) in this way..
then alter the value of each pixel to change the image..

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>

void main( )
{
    FILE *fp;
    unsigned char i[100][100;
    int m,n;
    clrscr();

    if((fp = fopen("lenna.dat","r+")) == 0)
    {
        printf("Just conat open the specified file.\n");
        exit(1);
    }
    else
    {
        for(m=0;m<100;m++)
        {
            for(n=0;n<100;n++)
            {
                fscanf(fp,"%c",&i[m][n]);
            }
        }
        fclose(fp);
getch();
}

hope this helps..
if u find a better way, tell me..

Thanx dalaharp .. ill try it out

j

I tried running it in vc++ , it gave me the foll errors. I add the image which i want to read into the resource file right??
Other than that i have another doubt
How do i modify it for accomodating a colour image?

The 2 errors

readimage.obj : error LNK2001: unresolved external symbol _clrscr
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ty

>error LNK2001: unresolved external symbol _clrscr
clrscr is a frivolous function that only an ignorant newbie or a blatant antisocial prick would use at the start of their program (and usually everywhere else too). You can safely remove it. You may also need to change getch to _getch to compile with Visual Studio. If you're able to link then clearly you've found and corrected the other errors.

in such compilers as VisualStudio .NET 2003 you need to use the system() command for clear screen it is something like System(cls); or something like that, and Narue I would like to state that running a program in a DOS window without the occasional claer screen will be quite messy and a clear screen just helps to keep it clean and neat. It is all for aesthetics. It doesn't make you an antisocial prick. Callign somebody that based on a clearscreen use is just ignorant, no offense.

>you need to use the system() command for clear screen
Just because it's available doesn't mean you should use it. There are three big reasons not to use system for this: Security, portability, and performance. You would do better to write your own screen clearing function using the Win32 API than to use system.

>I would like to state that running a program in a DOS window without the occasional claer screen will be quite messy
I would like to retort that clearing the screen when your program starts is antisocial because it removes all output from prior programs. I don't imagine you would be thrilled to have data that you intended to use for reference wiped out because some moron wanted things to look cleaner. If you're running from an IDE then clearing the screen at program start is stupid because it does nothing. The console window is empty to begin with.

>and a clear screen just helps to keep it clean and neat.
Who are you to judge whether a console that you don't own needs to be kept clean and neat? If you do own the window then by all means clear the screen if you think it improves life, but you only prove your idiocy by doing it on a fresh window. Really the only valid reason for clearing the console window in programs like these is for showing cute attention getters like paging menus and animation. There are better tools for such things, so you're only arguing in favor of cluelessness. And did I mention that there's absolutely no way to clear the screen portably?

>It doesn't make you an antisocial prick.
Clearly you've never been on the receiving end of a screen clear and had critical data wiped out. Therefore you're in no position to defend the newbies of the world.

>Callign somebody that based on a clearscreen use is just ignorant
No offense, but you seem to be the ignorant one in this case. You decided to champion a bad practice when you were unaware of the issues involved.

>no offense.
None taken, you made an honest try. :)

well well well guys, what all this???
hi narue..
i am a newbie and if i am not ignorant i might as well be a great genius like you and not an 'ignorant newbie'..
and what was the other thing u said, 'blatant antisocial prick'
well i thought this forum is for getting help and helping others and not for practising your fancy obnoxious comments on fellow members..
if u think my code has flaws, you have all the privileges to state so..
cause if u look back, i ha quoted.
"hope this helps..
if u find a better way, tell me.. "
:mad: with all due respect to your so called brilliance, 'you suck'..

nevertheless, ritcherjd, i tried this code on turbo C and is working fine..
i dont know what modification to make for vc++..
this code is to read a gray scale image in .raw format or .dat format..

commented: You may not know this, but you are the one being an ass. +0

>i am a newbie and if i am not ignorant i might as well be a great genius like you
Look up the definition of ignorant before you rant, please. It's not an insult, so stop acting defensive. Now, when I call you a moron, that's an insult and you're free to interpret it as such.

>and what was the other thing u said, 'blatant antisocial prick'
That's for the people who know the issues but still decide to use a bad construct. You clearly aren't in that camp, so it doesn't apply to you. If it did you would be completely within your rights to be insulted. ;)

>well i thought this forum is for getting help and helping others
I do help others. But you're too busy worrying about the harsh comments to see the help that was given. I'm not responsible for your inability to look past your own ego; that's a personal problem.

>and not for practising your fancy obnoxious comments on fellow members..
Actually, that's one of the main reasons I frequent this forum. I'm much nicer on the other sites I visit, and if one doesn't vent then it causes excess stress. When I stop helping people then you have a right to complain.

>cause if u look back, i ha quoted
This is clearly referring to the algorithm and not the poor framework. But if you'd like I can give you a full code review, detailing all of the flaws and pitfalls, because it does have serious problems as posted.

>with all due respect to your so called brilliance
You seem to think that I'm arrogant enough to consider myself a genius. I'm not, I don't, and not once have I ever implied that I do. You're mistaking confidence in my abilities with ego.

>'you suck'..
Get over yourself and at least make an attempt to learn what I tried to teach in this thread. I'm not here to make you feel good about yourself, I'm here to help you improve your programs. If I hurt your feelings at any point, I don't care because how you feel isn't a high priority for me.

well well - looks like this thread has blown out of proportion.. Could someone help me out with the other problem? How do i deal with a colour image (probably in .tiff format)? Think Narue can deal with this?? I am a newbie and am looking for some help....

ty
j

>How do i deal with a colour image (probably in .tiff format)?
The code for processing an image depends heavily on the image format. Go here and read up on the .tiff format to see what's involved.

What a lively thread!!!

I have been accused of using lame old Turbo C code in the past by our friend Narue, and heeded her salutary advice. I have to admit that I enjoy her comments a lot, and of course the always impeccable English. Please take it easy on Narue, she is a heck of a good programmer!!!

What a lively thread!!!

I have been accused of using lame old Turbo C code in the past by our friend Narue, and heeded her salutary advice. I have to admit that I enjoy her comments a lot, and of course the always impeccable English. Please take it easy on Narue, she is a heck of a good programmer!!!

Whaatttt? i thought Narue was a guy!!![img]http://daniweb.com/techtalkforums/techtalk-images/smilies/fiyellow/icon_lol.gif[/img]

Well she is a good programmer but an even better critic.

According to her profile she's a gal. Either that or the photo shows someone else :)

To add: you can get information on just about any fileformat you want at http://www.wotsit.org
Sometimes complete C or other code is included.

hi narue,
nice try..but i still think that you suck.. never mind..
the reason i posted that code with all the flaws and pitfalls as you have described it, is because i was also finding the same solution as ritcherjd and thought helping him will help me too..
well master (never mind what gender u are), i am willing to learn..
could you please tell me how a picture is encoded into a .dat (data file) format ?

and what are the flaws in my code??

thanks..

>nice try..but i still think that you suck
I'm sorry that my well informed arguments didn't penetrate your barrier of idiocy.

>the reason i posted that code <snip excuse>
That's nice. Next time say so to avoid teaching bad habits. And before you answer, "If you find a better way" doesn't count as a disclaimer that your code bites.

>could you please tell me how a picture is encoded into a .dat (data file) format ?
.dat isn't an image file format.

>and what are the flaws in my code??
Off the top of my head:

>#include <math.h>
You don't use any math routines, this can be removed.

>#include <conio.h>
Your use of conio functions is limited to poor examples that can be either avoided as stupid, or replaced with a standard function.

>void main( )
This makes your program completely undefined. The proper definition for main is

int main ( void )

or

int main ( int argc, char *argv[] )

if you process command line arguments.

>unsigned char i[100][100;
Syntax error, you forgot a closing square bracket.

>clrscr();
Unnecessary. It only serves to make your code nonportable.

>if((fp = fopen("lenna.dat","r+")) == 0)
There's no need to open this stream as an update stream. All you do is read from it, so the mode should be "r". Hardcoding the filename is also a bad practice. A better solution would be to ask the user for a file to open. Also, on a purely stylistic note, NULL is more descriptive than 0 when testing for a null pointer.

>exit(1);
1 isn't a portable argument for exit. A better choice would be EXIT_FAILURE, defined in stdlib.h.

>fscanf(fp,"%c",&i[m][n]);
That's a lot of work just to get the same effect as

i[m][n] = (unsigned char)fgetc ( fp );

There are also potential issues with mixing char and unsigned char in scanf, not to mention that i is an awful choice of names for your array.

>getch();
This can be replaced with getchar() at only a minor inconvenience to users that care.

next time i cut a chunk of code from a bigger program i will remember narue, and modify it b4 submitting it.
anyways i thought it is enough to get the message through than the aesthetic appeal of the code. (which some purist might oppose to)
but hey, thanks for the remarks.
and if .dat is not an image file format(ok), but images ARE encoded and represented in .dat format.
so it CAN be read by my code. and image processing operations can be done pixel wise.
or am i wrong again??

and if .dat is not an image file format(ok), but images ARE encoded and represented in .dat format.
so it CAN be read by my code. and image processing operations can be done pixel wise.
or am i wrong again??

You're right, but you have to know exactly how long is the file header, how the info is stored in the file, the encoding algorithm etc...

i guess that the .dat file does not have a file header, and the info is stored as data bits, and can be represented in an 2d array.
now moving a little further, how to rotate this image in an array.
see if i rotate it by 45degree, then the image falls out ofthe grid.
then image data is lost.
will resizing the array help, then the extra array elements added will have garbage data..
wont it???

my advice is that for a beginer first get an binary file of an image and read the file and display using put pixel statement in c.
As u r going to display black and white image u need to set an threshold value above which all the values should be displayed using black colour n rest r white.
Try out this.

commented: 4 YEARS TOO LATE!!! -5
commented: Look at the date of the last post before replying, please. -6

pleas can eny one help me in image segmentation in c+

commented: Here's a good thread, let's pile onto the end without reading it screaming "me too", "ME TOO!!!!!" -3

i think it is a worst site which inspite of giving reply for the searched topic reply with all non sense

commented: Don't bump old threads +0

my advice is that for a beginer first get an binary file of an image and read the file and display using put pixel statement in c.
As u r going to display black and white image u need to set an threshold value above which all the values should be displayed using black colour n rest r white.
Try out this.

I added some code to a program some years back for this. Helped out someone who had a program to enhance MRI images.

I'll have to scour around and find it. As I recall, the array should be unsigned char, and you open the file in binary mode. Raju D sounds like he's on the right path.

As others have mentioned, you need to understand the file format you'll be working with. (there are so many!. :p

@Narue, ygPM

commented: this thread is 5 years old. the person you are "responding" to posted 1-1/2 years ago. after 200 posts, you should know better than this -1

Hi,
i need a code in c for image processing to rotate an image 90 degree

hi..could someone help me or give me suggestion of a simple image processing..i'm a newbie and i want to know more about image processing...could someone give me an example of a simple digital image processing using of course, C..thanx=)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.