image processing

This is a discussion on image processing within the C Programming forums, part of the General Programming Boards category; Hi everyone, I have to write a set of C library routines to perform some actions on an image , ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    104

    image processing

    Hi everyone,
    I have to write a set of C library routines to perform some actions on an image , which is supplied by the user . The general requirements are :
    2) 3 options :
    - invert image pixels
    ( The function will IMPORT a
    2-D pixel array and EXPORT the resulting 2-D pixel array via the
    function mechanism. )

    - scroll image horiz
    ( The procedure will IMPORT a single 2D pixel array as well as a scroll
    amount and EXPORT the resulting 2D pixel array via the parameter
    list. )
    - scroll image vertic
    ( The procedure will IMPORT a single 2D pixel array as well as a scroll
    amount and EXPORT the resulting 2D pixel array via the parameter
    list. )
    I am studying on C libraries , but before I produce the final code, I need to do pseudocode for the program . Can someone point me in the right directions on how to handle this in terms of pseudocode. I have a good idea on importing/exporting arrays , but I'm having trouble understanding how I would import the image pixels. Any help is greatly appreciated.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Well the pixels would be stored in the arrays!

    If you're writing a general purpose image transformation, you don't need to care whether the original image came from BMP, JPG, PNG or GIF. Actual import and export from/to a given file format is a different problem (for you, or your library user).

    Essentially, you need
    - the format of the pixels (eg. 32-bit AARRGGBB say)
    - the width and height of the image
    - a pointer to the image data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Can you give me some more details. For example how would I get the image from the user ? Something like this ?
    Code:
    output "Enter image filename";
    input imagename;
    set filepath /usr/images/
    load image;
    output " Please enter size of image { width x height}"
    integer x , y
    array[x][y]<-- image //Convert image into an array

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Code:
    procedure invert(float,array)
    {
    Integer Max_y<--y
    Integer Max_x<--x
    Integer Current_y 
    Integer Current_x
    While Current_x less than Max_x;
    array[x]<--array[x-256] // meant to invert colour , by changing pixel value 
    EndWhile;
    While Current_y less than Max_y;
    array[y]<--array[y-256]; 
    EndWhile;
    }
    new <-- Invert(array x y);
    Something like this for a procedure that inverts the colour ?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Yes, something like that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    array[x]<--array[x-256] // meant to invert colour , by changing pixel value
    This looks like you would be writing pixels from one array location to another, not inverting the colour.


    If you want to invert an 8 bit greyscale colour then you should do something like:
    Code:
    array[x] = 255-array[x];
    This would subtract the original colour value from the maximum colour value. Effectively inverting it.

    If you are working with colour images you will need to invert each colour element (r, g, b) individually.

    Also to iterate through each item in a 2D array it might be a good idea to set your loops up something like:
    Code:
    for(y=0; y<height; y++)
    {
        for(x=0; x<width; x++)
        {
            //Do stuff here
        }
    }

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Any ideas on how I would do the scrolling of the image .
    - scroll image horiz
    ( The procedure will IMPORT a single 2D pixel array as well as a scroll
    amount and EXPORT the resulting 2D pixel array via the parameter
    list. )
    If I import the pixel values into an array , and then change these values aren't I just changing the colour of the picture ?
    Ihave some idea about getting the scroll ammount from 0 -1 , where 1 is 100&#37; scroll , but I don't know what to do then .

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Say you wanted to scroll
    12345
    to
    23451
    how would you do it?

    I think save '1', do a memmove() of the rest and then put the '1' back at the other end of the line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    I had that idea , but which part of the array would I be scrolling , becaue it's a 2d array .

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Well a horizontal scroll would affect each row the same, as above

    A vertical scroll would save the entire first row, then move all the rows.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Thanks Salem

    Code:
    /* memmove example */
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
      char str[] = "memmove can be very useful......";
      memmove (str+20,str+15,11);
      puts (str);
      return 0;
    }
    In this example , str+20 gets the end of the bit to be copied , str+15 gets the begining , and 11 provides the destination of the bit to be copied ?
    Code:
    memmove can be very very useful.
    why did the dots at the end go away ? Can you please explain what you mean by saving the 1 . Thanks a lot

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > why did the dots at the end go away ?
    Because you overwrote them with the memmove.

    > Can you please explain what you mean by saving the 1
    Well it's why your dots disappeared.
    memmove() doesn't know how to "insert" into an existing data structure.

    > and 11 provides the destination of the bit to be copied ?
    Did you RTM?
    It's the number of bytes to copy.

    Try scrolling "12345" using memmove
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    hey ICool, ur supposed to get the image from the command line argument and size is defined to a max of 1024 x 1024, if its bigger than that u have tp produce an error

  14. #14
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Cheers taurus,
    Have you finished the pseudo code already ?

  15. #15
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    haha not at all man, am not sure how to do it completly, u done much?
    Last edited by taurus; 10-14-2007 at 03:10 AM.

Page 1 of 6 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Simple Image Processing
    By ejohns85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2009, 12:10 PM
  3. Replies: 4
    Last Post: 03-02-2003, 08:12 AM
  4. Memory Allocation in Intell Image processing liberary
    By nisar in forum Windows Programming
    Replies: 0
    Last Post: 01-12-2003, 06:29 AM
  5. Image rotation using intel image processing
    By sunis in forum Windows Programming
    Replies: 1
    Last Post: 11-18-2002, 01:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21