Thread: Hello.I am new to programming. I need help with an algorithm for mangling a picture.

  1. #1
    Registered User
    Join Date
    Sep 2022
    Posts
    11

    Hello.I am new to programming. I need help with an algorithm for mangling a picture.

    Hello.


    Please can you give me some help with this?

    I have an algorithm which i want to do...and, -I call this C algorithm the "picture spiral-to-zig-zagging-cycle-algorithm"

    I have seen online documents (circa 2014 AD), and similar algorithms to what I want to do as to how to hide an image using a zig-zag--->to--->spiral mapping algorithm, again, in a similar manner to what I wanted to do... -and I was amazed to find that some other people on another part of the world had had the same idea as me.

    What a coincidence, great minds think alike, although my mind is net particularity great, -just creative.

    After all, I have one long ago, had the exact same idea sometime in 1994, when I was much younger.

    I was also very impressed as to some of the intelligence of others out in the wide world.

    (A bit beyond me, -really)!

    The only problem was that this zig-zag--->spiral image manipulation///modifier algorithm should really have been repeated///iterated for multiple, cycles, to see what effect that this had, -you know spiral--->row vector--->zig-zag
    --->row-vector--->spiral--->row vector--->zig-zag--->row vector--->spiral--->row vector--->zig-zag--->row vector--->spiral etc...etc...etc...

    So, I will tell you what...

    --->Please can you help me to manipulate an image of a pumpkin that I have had in my computer's hard-drive for a while now for:

    1, 2, 3, 5, 7, 10, 20, 30, 50, 70, 100, 200, 300, 500, 100, 2000, 300, 5000, 7000, 1000 cycles of:

    This process///this algorithm:

    1.Enter Pixelated High-Color Image,

    2.Make a matrix///an array out of it,

    3.Take horizontal square spirals(s) of image's pixels, working inward and from top-left to center of the picture's pixel's matrix...and place these in a row vector, moving left--->right, then...up--->down, then...right
    --->left...then...down--->up...

    4.Take the pixels from the row vector and place them in a zig-zag fashion into a new matrix so as to modify///mangle////manipulate the pumpkin-pictures pixies///image?

    5.This thus competes one cycle....

    6.Repeat steps 1.--->through--->5. Multiple times (as I mentioned above).

    I thought that interesting things might happen at cycle//iteration multiples of 200, 400 and 120000 for a 300 X 400 pixel picture.

    Please can we negotiate about these experiments, -and, I will stay in touch.

    Is this OK/alright that we do this?

    I am very interested and also fascinated to see what the results of all of this is/are...

    (I do have many other ideas, and as they say, two heads, when they co-operate are better than one--->This is also true for many heads make light work).

    I have a very childish algorithm in pseudo-code which I have done and I would like to post this on the c programming forum.

    Any ideas?

    Regards,

    Mr.SRU.

    P.S.Please realize that I am an ABSOLUTE BEGINNER to C programming and C algorithms, so i need all the help that I can get.


  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    You are with a very good start: Enumerating the steps! Now you need to detail them. For instance, what is the pixels format? RGB, RGBA, indexed? What is the size (width x height) of that image? Is it an usual format (PNG, JPEG, BMP?). Will you partition the image in little squares/rectangles? ...

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Before messing with the intricacies of an actual image, you can prototype what you need to do with simple code.

    Code:
    char image[5][5] = {
        { 'a', 'b', 'c', 'd', 'e' },
        { 'f', 'g', 'h', 'i', 'j' },
        { 'j', 'l', 'm', 'n', 'o' },
        { 'p', 'q', 'r', 's', 't' },
        { 'u', 'v', 'w', 'x', 'y' },
    };
    char vector[25];
    Your first exercise is to try and write some code that puts 'a', 'b', 'c', 'd', 'e', 'j', 'o', 't', 'y' etc into vector, by having some code go around image in the spiral.
    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.

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,734
    Hope I'm wrong but from your post it seems like you're trying to fob your own assignment off to the forum/s, if so what is the point in you taking C lessons if you don't learn to apply that C yourself, if I'm right then at least make an attempt yourself and post the result of your efforts (code I mean, not just the output), I'll give you a clue as where to start, a function for each type of action and a loop to call those functions.

  5. #5
    Registered User
    Join Date
    Sep 2022
    Posts
    11

    Further into Spiral To Zig-Zag image details

    Thanks for the prompt reply flp1969, this mean a lot to me!

    I do not know how to find the "pixels format", because, as I said, I am an ABSOLUTE BEGINNER, so any help would be appreciated.

    It was just an image of a pumpkin that I found somewhere online, that I used a Microsoft-Paint program to modify...

    ).

    The image does have some grey in it, so assumedly it might be RGBA.

    However can I find this information out?

    What does it mean for an image to be "indexed"?

    DO I have to modify it such that it IS indeed "indexed".

    The image size is:

    1267 by 851 pixels.

    The image is a *.jpg file.

    And, upon closer inspection, indeed, -it appears to be partitioned into little squares...

    Many thanks,

    Mr. SRU.

  6. #6
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    Yes, I know where you are coming from, but I know no other way that to learn and to meet new, people, =awsdert.

    Everywhere I do I get no responsive people, and people who do not reply to my messages, so I know no where else to go to.

    I really wasn't trying to fob anything off on anyone, and I am somewhat unsure of EXACTLY what you mean buy this..., but apart form that I am happy to learn.

    Mr. SRU.
    Last edited by ursellsarn; 09-28-2022 at 10:10 PM.

  7. #7
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    Well, Salem, here is some modified pseudo-code, whcih may contain some errors in it.

    I am an ABSOLUTE BEGINNER, so please go easy on me.
    Code:
    void PrintSpiralOfMatrixToArray(int m, int n, int image[5][5])
      {
      
    while (k<m && l<n)
        {
         /*Prints the first row from the remaining rows*/
         for(i=l;i<n;i++;)
            {
              copy character from matrix from position a[k][i] and print it in array position b;
              b++;
            }
          k++;
         /*Prints the last column from the remaining columns*/
         for(i=k; i<m; i++)
           {
             copy character from matrix from position a[i][n-1] and print it in array position b;
             b++;
           }
         n--;
         /*Prints the last row from the remaining rows*/
         if (k<m)
           {
              for(i=n-1;i>=l;i--;)
             {
                copy character from matrix from position a[m-1][i] and print it in array position b;
                b++;
             }
            m--;
           }
          /*Prints the last column from the remaining columns*/
         if(l<n)
              {for(i=m-1;i>=k;i--;)
                  {
                    copy character from matrix from position a[i][l] and print it in array position b;
                    b++;
                  }
             l++;
              }
          }
    
       }
    
    int main(){
    char image[5][5] = {
        { 'a', 'b', 'c', 'd', 'e' },
        { 'f', 'g', 'h', 'i', 'j' },
        { 'j', 'l', 'm', 'n', 'o' },
        { 'p', 'q', 'r', 's', 't' },
        { 'u', 'v', 'w', 'x', 'y' },
    };
    PrintSpiralOfMatrixToArray(5, 5, image);
    char vector[25];

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > I am an ABSOLUTE BEGINNER, so please go easy on me.
    So how many programming exercises have you done before trying to do this one?

    Whilst it isn't that hard to do in itself, if you're only one day past "hello world" your book, then it's going to be a challenge for sure.

    > Everywhere I do I get no responsive people, and people who do not reply to my messages, so I know no where else to go to.
    Well when your opening post is a long shopping list of requirements and no code effort, you do come across as needy/entitled looking to get free stuff.

    > here is some modified pseudo-code, whcih may contain some errors in it.
    It's a start, but you need to slow down.

    A key skill is being able to break a problem down into smaller and smaller steps until you get to something you can achieve.

    So start with the top row, like this.
    Code:
    #include <stdio.h>
    
    void printSpiral(int rows, int cols, char image[rows][cols]) {
        for ( int c = 0 ; c < cols ; c++ ) {
            printf("%c ", image[0][c] );
        }
        printf("\n");
    }
    
    int main ( ) {
        // Three increasingly complicated test cases
        char image1[1][6] = { // done on first L->R
            '{', '}', '[', ']', '(', ')',
        };
        char image2[2][4] = {  // done on first R->L
            { '1', '2', '3', '4' },
            { '5', '6', '7', '8' },
        };
        char image3[5][5] = {
            { 'a', 'b', 'c', 'd', 'e' },
            { 'f', 'g', 'h', 'i', 'j' },
            { 'j', 'l', 'm', 'n', 'o' },
            { 'p', 'q', 'r', 's', 't' },
            { 'u', 'v', 'w', 'x', 'y' },
        };
        printSpiral(1,6,image1);
        printSpiral(2,4,image2);
        printSpiral(5,5,image3);
    }
    
    $ gcc -std=c99 -pedantic foo.c
    $ ./a.out 
    { } [ ] ( ) 
    1 2 3 4 
    a b c d e
    Your first exercise is to enhance the function to print the right hand column.
    So your result is
    Code:
    { } [ ] ( ) 
    1 2 3 4 8
    a b c d e j o t y
    Then you try to add the code to print the bottom row.

    Then you try to add the code to print the left column.
    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.

  9. #9
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,734
    Quote Originally Posted by ursellsarn View Post
    Yes, I know where you are coming from, but I know no other way that to learn and to meet new, people, =awsdert.

    Everywhere I do I get no responsive people, and people who do not reply to my messages, so I know no where else to go to.

    I really wasn't trying to fob anything off on anyone, and I am somewhat unsure of EXACTLY what you mean buy this..., but apart form that I am happy to learn.

    Mr. SRU.
    To fob off means to leave the entirety of something to someone or something else, glad to see I was wrong though

  10. #10
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    Yes, I thought that was kind of weird you saying that, because in my country to "fob someone off" means to either to lie to them, or to sort of dismiss them in a patronizing/condescending manner.Oh the ironies of the International language/cultural barriers.

  11. #11
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,734
    Quote Originally Posted by ursellsarn View Post
    Yes, I thought that was kind of weird you saying that, because in my country to "fob someone off" means to either to lie to them, or to sort of dismiss them in a patronizing/condescending manner.Oh the ironies of the International language/cultural barriers.
    Well that is another usage of the word I forgot about, the difference can easily be seen in the context it is used so best remember both

  12. #12
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    <Salem says>

    So how many programming exercises have you done before trying to do this one?

    <Mr.SRU says>

    Next to none.

    I have experimented with generating prime numbers, prime ranks and prime ratios.

    As you mkight have guessed correctgly i am one day past Hello world!

    <Salem says>

    Whilst it isn't that hard to do in itself, if you're only one day past "hello world" your book, then it's going to be a challenge for sure.

    <Mr.SRU says>

    Well, let us hope that all goes smoothly.

    <Salem says>

    Well when your opening post is a long shopping list of requirements and no code effort, you do come across as needy/entitled looking to get free stuff.

    <Mr. SRU says>

    Yes, very good point.

    <Salem says>

    It's a start, but you need to slow down.

    <Mr. SRU says>

    Yes, very another good point.

    <Mr. SRU says>

    A key skill is being able to break a problem down into smaller and smaller steps until you get to something you can achieve.

    So start with the top row, like this.

    <Salem says>

    Your first exercise is to enhance the function to print the right hand column...

    Then you try to add the code to print the bottom row...

    Then you try to add the code to print the left column...

    <Mr. SRU says>

    Yes, in due course I will work on it.

  13. #13
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    Yes, I understand completely.

  14. #14
    Registered User
    Join Date
    Sep 2022
    Posts
    11
    Thankyou Salem, indeed, -you are a very good, patient, nice teacher/tutor.

    )

    I put quite a bit of thought into this last night after a few cups of coffee...

    ...and I came up with:

    Code:
    void printSpiral(int rows, int cols, char image[rows][cols])
    {
     for ( int c = 0 ; c < cols ; c++ ) 
        {       
       printf("%c ", image[0][c] );//Works across ways left to right
        }
    
     for (int r = 1 ; r <= rows ; r++ ) {
            printf("%r ", image[r][cols] );
        }
        printf("\n");//Works downwards top to bottom
    
    for (int c = cols-1 ; c >= 0 ; c-- ) 
        {
            printf("%c ", image[rows][c] );
        }
        printf("\n");//Works across ways right to left
    
    
    for (int r = rows-1 ; r >=1 ; r-- ) 
        {
            printf("%r ", image[r][0] );//Works upwards bottom to top
        }
        printf("\n");//
    }
    Can you seee any errors?

    Have I made any mistakes?

    Any thoughts on the matter?

    So, putting it all togther, it is:

    Code:
    #include <stdio.h>
    
    void printSpiral(int rows, int cols, char image[rows][cols]) 
    {
        
        for ( int c = 0 ; c < cols ; c++ ) 
           {
            printf("%c ", image[0][c] );//Works across ways left to right
           }
            printf("\n");
        
    
        for (int r = 1 ; r <= rows ; r++ ) 
           {
            printf("%r ", image[r][cols] );
           }
            printf("\n");//Works downwards top to bottom
    
      for (int c = cols-1 ; c >= 0 ; c-- ) 
           {
             printf("%c ", image[rows][c] );
           }
             printf("\n");//Works across ways right to left
    
    for (int r = rows-1 ; r >=1 ; r-- )
          {
            printf("%r ", image[r][0] );
          }
         printf("\n");//Works upwards bottom to top
    }
    
    int main ( ) 
    {
        char image3[5][5] = 
       {
            { 'a', 'b', 'c', 'd', 'e' },
            { 'f', 'g', 'h', 'i', 'j' },
            { 'j', 'l', 'm', 'n', 'o' },
            { 'p', 'q', 'r', 's', 't' },
            { 'u', 'v', 'w', 'x', 'y' },
       };
    printSpiral(rows, cols, image);
    }
    I hope this helps,

    Thanks,

    Mr. SRU.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    I deleted the off-track-tangential-ramblings.

    Basically, stick to your own path, write your own code, in your own time, learning at your own pace.

    Anyway, back on topic.

    Back in post #14, you said.
    > Can you seee any errors?
    > Have I made any mistakes?
    Those are questions you can answer for yourself.
    Does it do what you set out to do - print the outside edge of the given rectangle.

    FWIW, it doesn't actually compile, so that's something you need to address when you post code.
    If you want on point comments on your code, it needs to actually compile, even if it doesn't do what you want.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-27-2012, 07:23 AM
  2. shared libraries in c++ name mangling error
    By mayank.gupta22 in forum Linux Programming
    Replies: 7
    Last Post: 02-13-2012, 05:11 PM
  3. stdcall name mangling on Widnows
    By Uwar in forum C Programming
    Replies: 0
    Last Post: 06-05-2010, 05:13 AM
  4. Clickie mangling?
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-14-2002, 12:31 AM
  5. picture
    By anonymous in forum C Programming
    Replies: 1
    Last Post: 01-29-2002, 02:44 AM

Tags for this Thread