[완료]이미지 회전 질문드려도 될까요 'ㅂ'

onam3125의 이미지

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
 
 
void main()
{
 unsigned char *in_frame;
 unsigned char *out_frame;
 unsigned char *temp;
 
 int i,j;
 FILE *fp_read, *fp_write;
 
 in_frame    =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 out_frame   =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 temp   =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 
 fp_read = fopen("Lena(512x512).raw","rb");
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(in_frame + i*512 + j)=(unsigned char)getc(fp_read);
  }
 }//정의
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
 
   *(out_frame + (511-i)*512 + j) = *(in_frame + i*512 + j);
 }//상하대칭
 
 
 fp_write=fopen("save_lena.raw","wb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + i*512 + j),fp_write);
  }
 }
 fclose(fp_read);
 fclose(fp_write);//파일 닫기
 
 fp_read = fopen("save_lena.raw","rb");
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(in_frame + i*512 + j)=(unsigned char)getc(fp_read);
  }
 }//재정의
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(out_frame + i*512 + (511-j) ) = *(in_frame + i*512 + j);
  }
 }//180도 회전을 위한 좌우대칭
 fp_write=fopen("[Rotate_180]Lena(512x512).raw","wb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + i*512 + j),fp_write);
  }
 }//출력부분
 
 fclose(fp_read);
 fclose(fp_write);//파일닫기 1
 
 fp_read = fopen("save_lena.raw","rb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(in_frame + i*512 + j)=(unsigned char)getc(fp_read);
  }
 }//재정의2/
 
 for(i=0;i<(512);i++)
 {
  for(j=512;j>(0);j--)
  {
   temp[i] = in_frame[i];
   in_frame[i] = out_frame[j];
   out_frame[j] = temp[i];
  }
 }
 
 //왼쪽90도 회전
 fp_write=fopen("[Rotate_90]Lena(512x512).raw","wb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + i*512 + j),fp_write);
  }
 }
 
 fclose(fp_read);
 fclose(fp_write);
 
 free(in_frame);
 free(out_frame);
}

일단 실행은 제대로 되는데...180도 회전하는것도 구현이 됬는데...
90도 회전파일이 180도 회전 파일이랑 상태가 같네요 ㅠㅠ....
90도 회전도 제대로 구현한지도 모르겠고...맞는거 가튼데...적용이 안되나...
싶어서 디버깅 돌리면 적용은 되는데...알고리즘이 틀렸나 싶어서

90도 회전 부분 싹다 지워놓고 출력해도 180도랑 똑같고...으허..

90도 회전한것도 90도 회전한걸로 나오게 하려면 어떻게 해야하나요

onam3125의 이미지

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
 
 
void main()
{
 unsigned char *in_frame;
 unsigned char *out_frame;
 unsigned char *temp;
 
 int i,j;
 FILE *fp_read, *fp_write;
 
 in_frame    =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 out_frame   =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 temp   =(unsigned char *)malloc(sizeof(unsigned char)*512*512);
 
 fp_read = fopen("Lena(512x512).raw","rb");
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(in_frame + i*512 + j)=(unsigned char)getc(fp_read);
  }
 }//정의
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
 
   *(out_frame + (511-i)*512 + j) = *(in_frame + i*512 + j);
 }//상하대칭
 
 
 fp_write=fopen("save_lena.raw","wb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + i*512 + j),fp_write);
  }
 }
 fclose(fp_read);
 fclose(fp_write);//파일 닫기
 
 fp_read = fopen("save_lena.raw","rb");
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(in_frame + i*512 + j)=(unsigned char)getc(fp_read);
  }
 }//재정의
 
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   *(out_frame + i*512 + (511-j) ) = *(in_frame + i*512 + j);
  }
 }//180도 회전을 위한 좌우대칭
 fp_write=fopen("[Rotate_180]Lena(512x512).raw","wb");
 for(i=0;i<(512);i++)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + i*512 + j),fp_write);
  }
 }//출력부분
 
 
 fclose(fp_write);//파일닫기 1
 
 
 fp_write=fopen("[Rotate_90]Lena(512x512).raw","wb");
 for(i=512;i>(0);i--)
 {
  for(j=0;j<(512);j++)
  {
   putc(*(out_frame + j*512 + i),fp_write);
  }
 }//90도 회전하여 출력하기
 
 fclose(fp_read);
 fclose(fp_write);
 
 free(in_frame);
 free(out_frame);
}
익명 사용자의 이미지

180도 회전은 90도 회전을 두 번 하는 것이니까.
90도 회전 부분만 구현하시고, 180도 회전이 필요할 때는 90도 회전을 두번 하는 방식으로 하는게 좋겠죠.

그리고 90도 회전(반시계방향)은 행렬 연산의 transpose, 상하 flip으로도 가능합니다.
pseud 코드를 아래와 같습니다.

Mat src = new Mat(rows, cols);
Mat dst = new Mat(cols, rows);
 
// rotate 90 degree, counterclockwise
dst = Matrix.transpose(src);
dst = Matrix.flipVertical(dst);

transpose 할 때 행과 열의 크기에 조심하셔야합니다. 질문자께선 정사각형 행렬만 고려하셨더군요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.