Image processing is done in C language.I want to rotate the image 90 degrees.

Asked 2 years ago, Updated 2 years ago, 107 views

This is the extraction of the program's main function.If I do this, it should rotate 90 degrees, but I can't.As a countermeasure,

  • Turn the loop based on the size of img_out
     → Adjust the index of img_in to substitute a value for img_out[i][j]
  • Turn the loop based on the size of the img_in
     → I think it would be better to adjust the index of img_out to which img_in[i][j] is to be substituted, but I don't know what to do with it even if I know.I'd like a hint or a specific example.
int main(intargc, char*arge[]){
    structure img_data img_org, img_out;

    /* Image loading*/
    img_org = img_from_pgm(arge[1]);

    /*Image Processing*/
    img_out=ImageProcessing(img_org);

    /* Image Export*/
    img_to_pgm(img_out, age[2]);
    return1;
}
/*Image Processing*/
struct img_data ImageProcessing(struct img_data img_in){
    inti,j;
    structure img_data img_out;
    /* Image preparation for output*/
    img_out=img_set(img_in.ysize, img_in.xsize);
    /* Processing Department*/
    for(j=0;j<img_in.ysize;j++)
        for(i=0;i<img_in.xsize;i++){
            img_out.data[i][j]=img_in.data[img_in.xsize-j-1][i];/*???*/
        }

    /* Return Processing Results */
    return img_out;
}

c image

2022-09-30 21:48

2 Answers

(I don't know exactly what the inability to execute refers to.) At least the coordinate transformation seems wrong.
I think it's easier to draw a diagram and think about the coordinates before and after rotation.

Enter a description of the image here


2022-09-30 21:48

Image Processing

for 90 degree left rotation
img_out.data[i][j]=img_in.data[img_in.xsize-j-1][i];

If you change to the following, it will work.

img_out.data[i][j]=img_in.data[j][img_in.xsize-j-1];

I thought it would be easier to focus on INPUT instead of OUTPUT.

img_out.data[img_in.xsize-i-1][j]=img_in.data[j][i];

In my opinion, it would be better to draw pictures and build logic.

Input data
+--+--+--+
| 1| 2| 3|
+--+--+--+
| 4| 5| 6|
+--+--+--+
| 7| 8| 9|
+--+--+--+
|10|11|12|
+--+--+--+
output data
+--+--+--+--+
| 3| 6| 9|12|
+--+--+--+--+
| 2| 5| 8|11|
+--+--+--+--+
| 1| 4| 7|10|
+--+--+--+--+


2022-09-30 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.