2011년 9월 26일 월요일

Install MingW and SDL.

* Goto http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get/


* Download mingw-get-inst-xxxxxx.exe

* Execute MingW Shell




* Execute "mingw-get update" and "mingw-get upgrade"


* Download SDL-X.X.X-win32.zip under Win32 of Runtime Libraries and SDL-devel-X.X.X-mingw32.tar.gz under Win32 of Development Libraries.


* Extract SDL-devel-X.X.X-win32.zip.
* Copy libSDLmain.a, libSDL.la, and libSDL.dll.a into into $(MingW Directory)/lib/*.a.
* Copy include/SDL/* into $(MingW Directory)/include/SDL.
* Copy bin/SDL.dll and bin/sdl-config into $(MingW Directory)/bin.


2011년 9월 25일 일요일

Using delaunay trianglulation, thinning of a mass object.

Thinning algorithm based on morphology operation is not adopted for a mass object on image. It needs too many operations. To down-size a processing time one of the other methods is based on delaunay triangulation.


For a triangle having a edge in outside of a mass object, it is out of consideration.


Blue-colored triangles are out of consideration. And then it needs analysis the relationship of connectivity between triangles. A few definitions are enlisted. the End Triangle is defined as two edges of triangle meet outside of mass object, the Edge Triangle is defined as one edge of triangle meets outside of mass object, and the Branch Triangle is defined as none edge of triangle meets outside of mass object.



Blue-colored triangle indicates a End Triangle, Green-colored triangle indicates a Edge Triangle, and red-colored triangle indicates a Branch Triangle. According to connectivity among three types of triangles, the center of innercircle of End and Branch Triangle forms thinning lines.








2011년 9월 22일 목요일

Fixing delaunay triangulation

During delaunay triangulation unexpacted line crossing is performed.
Given points are like this.



And Its result is


Its code is


void delaunay_list_create_2d_network(delaunay_list_t *list, point_list_t *points, bitmap_t *roi)
{
  dlink_t *x, *y, *z;
  point_t *o, *a, *b, *c;
  point_t *v1, *v2, *v3, *org;
  delaunay_net_t *neta, *netb, *netc, *net;
  //dlist_t *triangles;
  triangle_list_t *triangles;
  triangle_t *tri;
  //dlist_t *lines;
  line_list_t *lines;
  line_t *line, *l;
  real_t da, db, dc, s;
  real_t val, vmin;
  real_t radius, area;

  assert(list);
  assert(points);

  // allocate delaunay network list
  //list = delaunay_list_new();
  for (x = points->tail->next; x != points->head; x = x->next) {
    net = delaunay_net_new((point_t *)x->object);
    delaunay_list_insert(net, list);
  }

  // starting point
  neta = delaunay_list_get_net(0, list);
  a = delaunay_net_get_coordinate(neta);
  // find minimum distance between points
  for (netb = NULL, x = list->tail->next->next; x != list->head; x = x->next) {
    net = (delaunay_net_t *)x->object;
    o = delaunay_net_get_coordinate(net);
    val = distance_between_points(a, o);
    if (val < REAL_EPSILON) continue;
    if (netb == NULL || val < vmin) { netb = net; vmin = val; }
  }

  b = delaunay_net_get_coordinate(netb);
  // find minimum radius of circumscribed circle for triangle
  for (netc = NULL, x = list->tail->next->next; x != list->head; x = x->next) {
    net = (delaunay_net_t *)x->object;
    if (net == netb) continue;
    o = delaunay_net_get_coordinate(net);
    // Heron's formula to find the area formed by three points
    da = distance_between_points(a, b);
    db = distance_between_points(b, o);
    dc = distance_between_points(o, a);
    s = (da + db + dc) / 2;
    area = sqrt(s * (s - da) * (s - db) * (s - dc));
    if (area < REAL_EPSILON) continue;
    // calculate radius of circumscribed circle for triangle
    radius = (da * db * dc) / (4 * area);
    if (netc == NULL || radius < vmin) { netc = net; vmin = radius; }
  }
  c = delaunay_net_get_coordinate(netc);

  v1 = point_new();
  v2 = point_new();
  v3 = point_new();
  org = point_new();

  // re-ordering
  point_subtract(v1, b, a);
  point_subtract(v2, c, a);
  point_xproduct(v3, v1, v2);
  if (v3->z > 0) { // counterclockwise following a to b to c ?
    net = netb, netb = netc, netc = net;
    o = b, b = c, c = o;
  }

  // connect delaunay network
  delaunay_net_connect(neta, netb);
  delaunay_net_connect(netb, netc);
  delaunay_net_connect(netc, neta);

  // Synthesize a triangle and insert it.
  //triangles = dlist_new();
  triangles = triangle_list_new();
  tri = triangle_new_and_assign(a, b, c);
  triangle_list_insert(tri, triangles);

  //triangle_dump(tri);
  // Synthesize three line and insert it.
  lines = line_list_new();
  line = line_new_and_assign(a, b);
  line_list_insert(line, lines);
  line = line_new_and_assign(b, c);
  line_list_insert(line, lines);
  line = line_new_and_assign(c, a);
  line_list_insert(line, lines);

  // main routine
  for (x = lines->tail->next; x != lines->head; x = x->next) {
    line = (line_t *)x->object;
    //line_dump(line);
    for (y = list->tail->next; y != list->head; y = y->next) {
      netc = (delaunay_net_t *)y->object;
      c = delaunay_net_get_coordinate(netc);
      if (point_cmp(c, line->a) == 0 || point_cmp(c, line->b) == 0)
continue;
      // counter-clockwise rotation of the triangle formed by a, b, and c
      point_subtract(v1, line->b, line->a);
      point_subtract(v2, c, line->a);
      point_xproduct(v3, v1, v2);
      if (v3->z < REAL_EPSILON) continue;
      // Does the triangle exist in the pool of delaunay triangles before ?
      tri = triangle_new_and_assign(line->a, c, line->b);
      //if (is_triangle_in_list(tri, triangles)) {
      if (triangle_list_query(tri, triangles) >= 0) {
triangle_destroy(tri);
tri = NULL;
continue;
      }
      // Does the unique triangle form the delaunay triangle ?
      radius = triangle_circumcircle(org, tri);
      for (z = list->tail->next; z != list->head; z = z->next) {
net = (delaunay_net_t *)z->object;
o = delaunay_net_get_coordinate(net);
if (point_cmp(o, line->a) == 0 ||
   point_cmp(o, line->b) == 0 ||
   point_cmp(o, c) == 0)
 continue;
if (distance_between_points(o, org) < radius) {
 triangle_destroy(tri);
 tri = NULL;
 break;
}
      }

      if (tri) {
/* put the trinangle into triangle's list,
* establish connection between delaunay networks, and
* allocate and put two lines into line's list */
triangle_list_insert(tri, triangles);
l = line_new_and_assign(line->a, c);
if (line_list_query(l, lines) < 0) {
 line_list_insert(l, lines);
 for (z = list->tail->next; z != list->head; z = z->next) {
   net = (delaunay_net_t *)z->object;
   o = delaunay_net_get_coordinate(net);
   if (point_cmp(o, line->a) == 0) {
     delaunay_net_connect(netc, net);
     break;
   }
 }
} else line_destroy(l);

l = line_new_and_assign(c, line->b);
if (line_list_query(l, lines) < 0) {
 line_list_insert(l, lines);
 for (z = list->tail->next; z != list->head; z = z->next) {
   net = (delaunay_net_t *)z->object;
   o = delaunay_net_get_coordinate(net);
   if (point_cmp(o, line->b) == 0) {
     delaunay_net_connect(netc, net);
     break;
   }
 }
} else line_destroy(l);
break;
      }
    }
  }

  // de-allocation lines and triangles
  /*
  while (triangles->count) {
    tri = triangle_list_pop(triangles);
    //triangle_dump(tri);
    triangle_destroy(tri);
  }
  triangle_list_destroy(triangles);
  */
  list->head->object = (void *)triangles;

  while (lines->count) {
    line = line_list_pop(lines);
    //line_dump(line);
    line_destroy(line);
  }
  line_list_destroy(lines);

  point_destroy(v1);
  point_destroy(v2);
  point_destroy(v3);
  point_destroy(org);

  //  return list;
}


Its reason is because of four points on the same circle. Delaunay Triangulation is determined by whether there is a point in circumference circle, but for this four points it is impossible to construct the unique delaunay triangulation.


The triangle with red color has properties like this;
three vertex: (333, 311), (333, 183), (308, 315)
center of circumference circle: (309.94, 247)
radius of circumference circle: 68.027688

The triangle with blue color has properties like this;
three vertex: (308, 315), (333, 311), (308, 179)
center of circumference circle: (309.94, 247)
radius of circumference circle: 68.027688

In this case it is necessary that additional algorithm is to avoid a crossing between lines.

The subroutine to detect whether two lines has intersecting point or not. It is referenced at http://paulbourke.net/geometry/lineline2d/


int intersect_point_between_lines(point_t *p, line_t *l, line_t *m)
{
  real_t denom, ua, ub;

  assert(p);
  assert(l);
  assert(m);

  // Pl = l->a + Ua * (l->b - l->a)
  // Pm = m->a + Ub * (m->b - m->a)
  // for Pl = Pm
  denom = (m->b->y - m->a->y) * (l->b->x - l->a->x) - (m->b->x - m->a->x) * (l->b->y - l->a->y);
  ua = (m->b->x - m->a->x) * (l->a->y - m->a->y) - (m->b->y - m->a->y) * (l->a->x - m->a->x);
  ub = (l->b->x - l->a->x) * (l->a->y - m->a->y) - (l->b->y - l->a->y) * (l->a->x - m->a->x);

  if (abs(denom) < REAL_EPSILON) {
    if (abs(ua) < REAL_EPSILON && abs(ub) < REAL_EPSILON)
      return 0; // COINCIDENT
    return -1; // PARALLEL
  }

  ua = ua / denom;
  ub = ub / denom;

  if (ua < 0 || ua > 1 || ub < 0  || ub > 1)
    return -2; // Not intersecting

  p->x = l->a->x + ua * (l->b->x - l->a->x);
  p->y = l->a->y + ua * (l->b->y - l->a->y);

  if ((abs(ua) < REAL_EPSILON || abs(ua - 1.0) < REAL_EPSILON) ||
      (abs(ub) < REAL_EPSILON || abs(ub - 1.0) < REAL_EPSILON))
    return 2; // ENDPOINT

  return 1; // INTERSECTING
}

And the code of modified delaunay triangulation is here.

void delaunay_list_create_2d_network(delaunay_list_t *list, point_list_t *points, bitmap_t *roi)
{
  dlink_t *x, *y, *z;
  point_t *o, *a, *b, *c;
  point_t *v1, *v2, *v3, *org;
  delaunay_net_t *neta, *netb, *netc, *net;
  //dlist_t *triangles;
  triangle_list_t *triangles;
  triangle_t *tri;
  //dlist_t *lines;
  line_list_t *lines;
  line_t *line, *l, *m;
  real_t da, db, dc, s;
  real_t val, vmin;
  real_t radius, area;

  assert(list);
  assert(points);

  // allocate delaunay network list
  //list = delaunay_list_new();
  for (x = points->tail->next; x != points->head; x = x->next) {
    net = delaunay_net_new((point_t *)x->object);
    delaunay_list_insert(net, list);
  }

  // starting point
  neta = delaunay_list_get_net(0, list);
  a = delaunay_net_get_coordinate(neta);
  // find minimum distance between points 
  for (netb = NULL, x = list->tail->next->next; x != list->head; x = x->next) {
    net = (delaunay_net_t *)x->object;
    o = delaunay_net_get_coordinate(net);
    val = distance_between_points(a, o);
    if (val < REAL_EPSILON) continue;
    if (netb == NULL || val < vmin) { netb = net; vmin = val; }
  }

  b = delaunay_net_get_coordinate(netb);
  // find minimum radius of circumscribed circle for triangle
  for (netc = NULL, x = list->tail->next->next; x != list->head; x = x->next) {
    net = (delaunay_net_t *)x->object;
    if (net == netb) continue;
    o = delaunay_net_get_coordinate(net);
    // Heron's formula to find the area formed by three points
    da = distance_between_points(a, b);
    db = distance_between_points(b, o);
    dc = distance_between_points(o, a);
    s = (da + db + dc) / 2;
    area = sqrt(s * (s - da) * (s - db) * (s - dc));
    if (area < REAL_EPSILON) continue;
    // calculate radius of circumscribed circle for triangle
    radius = (da * db * dc) / (4 * area);
    if (netc == NULL || radius < vmin) { netc = net; vmin = radius; }
  }
  c = delaunay_net_get_coordinate(netc);

  v1 = point_new();
  v2 = point_new();
  v3 = point_new();
  org = point_new();

  // re-ordering
  point_subtract(v1, b, a);
  point_subtract(v2, c, a);
  point_xproduct(v3, v1, v2);
  if (v3->z > 0) { // counterclockwise following a to b to c ?
    net = netb, netb = netc, netc = net;
    o = b, b = c, c = o;
  }

  // connect delaunay network
  delaunay_net_connect(neta, netb);
  delaunay_net_connect(netb, netc);
  delaunay_net_connect(netc, neta);

  // Synthesize a triangle and insert it.
  //triangles = dlist_new();
  triangles = triangle_list_new();
  tri = triangle_new_and_assign(a, b, c);
  triangle_list_insert(tri, triangles);

  //triangle_dump(tri);
  // Synthesize three line and insert it.
  lines = line_list_new();
  line = line_new_and_assign(a, b);
  line_list_insert(line, lines);
  line = line_new_and_assign(b, c);
  line_list_insert(line, lines);
  line = line_new_and_assign(c, a);
  line_list_insert(line, lines);

  // main routine
  for (x = lines->tail->next; x != lines->head; x = x->next) {
    line = (line_t *)x->object;
    //line_dump(line);
    for (y = list->tail->next; y != list->head; y = y->next) {
      netc = (delaunay_net_t *)y->object;
      c = delaunay_net_get_coordinate(netc);
      if (point_cmp(c, line->a) == 0 || point_cmp(c, line->b) == 0)
continue;
      // counter-clockwise rotation of the triangle formed by a, b, and c
      point_subtract(v1, line->b, line->a);
      point_subtract(v2, c, line->a);
      point_xproduct(v3, v1, v2);
      if (v3->z < REAL_EPSILON) continue;
      // Does any line crossing with line in the line list ?
      l = line_new_and_assign(line->a, c);
      m = line_new_and_assign(c, line->b);
      for (z = lines->tail->next; z != lines->head; z = z->next) {
// Is there an intersecting ?
if ((intersect_point_between_lines(v3, l, (line_t *)z->object) == 1) ||
   (intersect_point_between_lines(v3, m, (line_t *)z->object) == 1)) {
 line_destroy(l); l = NULL;
 line_destroy(m); m = NULL;
 break;
}
      }
      if (l == NULL && m == NULL) continue;

      // Does the triangle exist in the pool of delaunay triangles before ?
      tri = triangle_new_and_assign(line->a, c, line->b);
      //if (is_triangle_in_list(tri, triangles)) {
      if (triangle_list_query(tri, triangles) >= 0) {
triangle_destroy(tri);
tri = NULL;
continue;
      }
      // Does the unique triangle form the delaunay triangle ?
      radius = triangle_circumcircle(org, tri);
      for (z = list->tail->next; z != list->head; z = z->next) {
net = (delaunay_net_t *)z->object;
o = delaunay_net_get_coordinate(net);
if (point_cmp(o, line->a) == 0 ||
   point_cmp(o, line->b) == 0 ||
   point_cmp(o, c) == 0)
 continue;
if (distance_between_points(o, org) < radius) {
 triangle_destroy(tri);
 tri = NULL;
 break;
}
      }

      if (tri) {
/* put the trinangle into triangle's list, 
* establish connection between delaunay networks, and
* allocate and put two lines into line's list */
triangle_list_insert(tri, triangles);
//triangle_dump(tri);
//point_dump(org);
//printf("radius: %lf\n", radius);
//l = line_new_and_assign(line->a, c);
if (line_list_query(l, lines) < 0) {
 line_list_insert(l, lines);
 //line_dump(l);
 for (z = list->tail->next; z != list->head; z = z->next) {
   net = (delaunay_net_t *)z->object;
   o = delaunay_net_get_coordinate(net);
   if (point_cmp(o, line->a) == 0) {
     delaunay_net_connect(netc, net);
     break;
   }
 }
} else line_destroy(l);
//m = line_new_and_assign(c, line->b);
if (line_list_query(m, lines) < 0) {
 line_list_insert(m, lines);
 //line_dump(m);
 for (z = list->tail->next; z != list->head; z = z->next) {
   net = (delaunay_net_t *)z->object;
   o = delaunay_net_get_coordinate(net);
   if (point_cmp(o, line->b) == 0) {
     delaunay_net_connect(netc, net);
     break;
   }
 }
} else line_destroy(m);
//keyhit();
break;
      }
    }
  }

  // de-allocation lines and triangles
  /*
  while (triangles->count) {
    tri = triangle_list_pop(triangles);
    //triangle_dump(tri);
    triangle_destroy(tri);
  }
  triangle_list_destroy(triangles);
  */
  list->head->object = (void *)triangles;

  while (lines->count) {
    line = line_list_pop(lines);
    //line_dump(line);
    line_destroy(line);
  }
  line_list_destroy(lines);

  point_destroy(v1);
  point_destroy(v2);
  point_destroy(v3);
  point_destroy(org);

  //  return list;
}

At result the line crossing is disappeared.


Unfortunately, two delaunay triangles are deleted in the figure. In the figure dot is the mean center of delaunay triangle. As you see, you can find two triangles without mean center. It is remaining side effect of four points on the same circle. 


So, it needs to change comparison between variables expressed in floating points.

Change
....

    // Does the unique triangle form the delaunay triangle ?
      radius = triangle_circumcircle(org, tri);
      for (z = list->tail->next; z != list->head; z = z->next) {
net = (delaunay_net_t *)z->object;
o = delaunay_net_get_coordinate(net);
if (point_cmp(o, line->a) == 0 ||
    point_cmp(o, line->b) == 0 ||
    point_cmp(o, c) == 0)
  continue;
if (distance_between_points(o, org) < radius) {
  triangle_destroy(tri);
  tri = NULL;
  break;
}
      }
....
to
....

    // Does the unique triangle form the delaunay triangle ?
      radius = triangle_circumcircle(org, tri);
      for (z = list->tail->next; z != list->head; z = z->next) {
net = (delaunay_net_t *)z->object;
o = delaunay_net_get_coordinate(net);
if (point_cmp(o, line->a) == 0 ||
    point_cmp(o, line->b) == 0 ||
    point_cmp(o, c) == 0)
  continue;

val = distance_between_points(o, org);
if ((val < radius) && (round(100*val) < round(100*radius)) {
  triangle_destroy(tri);
  tri = NULL;
  break;
}
      }
....

Then,




2011년 9월 18일 일요일

Watershed by immersion (Vincent-Soille watershed algorithm)

procedure: Watershed-by-Immersion
Input: digital grey scale image G = (D;E; im).
Output: labelled watershed image lab on D.

#define INIT   1 // initial value of lab image
#define MASK   2 // initial value at each level
#define WSHED 0 // label of the watershed pixels
#define FICTITIOUS (-1, -1)  // fictitious pixel 2 D

curlab <= 0; // curlab is the current label
fifo_init(queue);

for all p in D do
   lab[p] <= INIT;
   dist[p] <= 0; // dist is a work image of distances
end for

SORT pixels in increasing order of grey values (minimum hmin, maximum hmax)

// Start Flooding
for h = hmin to hmax do // Geodesic SKIZ of level h   1 inside level h

   for all p in D with im[p] = h do // mask all pixels at level h
             // these are directly accessible because of the sorting step
      lab[p] <= MASK;
      if p has a neighbour q with (lab[q] > 0 or lab[q] == WSHED) then
         // Initialize queue with neighbours at level h of current basins or watersheds
         dist[p] <= 1;
         fifo_add(p, queue);
      end if
   end for

   curdist <= 1;
   fifo_add(FICTITIOUS, queue);

   loop // extend basins
      p <= fifo_remove(queue);
      if p == FICTITIOUS then
         if fifo_empty(queue) then
            break;
         else
            fifo_add(FICTITIOUS, queue);
            curdist <= curdist + 1;
            p <= fifo_remove(queue);
         end if
      end if
      for all q in neighbours of p do // labelling p by inspecting neighbours
         if dist[q] < curdist and (lab[q] > 0 or lab[q] == WSHED) then
            // q belongs to an existing basin or to watersheds
            if lab[q] > 0 then
               if lab[p] == MASK or lab[p] == WSHED then
                  lab[p] <= lab[q];
               else if lab[p] != lab[q] then
                  lab[p] <= WSHED;
               end if
            else if lab[p] == MASK then
               lab[p] <= WSHED;
            end if
         else if lab[q] == MASK and dist[q] == 0 then // q is plateau pixel
            dist[q] <= curdist + 1;
            fifo_add(q, queue);
         end if
      end for
   end loop

   // detect and process new minima at level h
   for all p in D with im[p] = h do
      dist[p] <= 0; // reset distance to zero
      if lab[p] == MASK then // p is inside a new minimum
         curlab <= curlab + 1;  // create new label
         fifo_add(p, queue);
         lab[p] <= curlab;
         while not fifo_empty(queue) do
            q <= fifo_remove(queue);
            for all r in neighbours of q do // inspect neighbours of q
               if lab[r] == MASK then
                  fifo_add(r, queue);
                  lab[r] <= curlab;
               end if
            end for
         end while
      end if
   end for
end for
// End Flooding

Reference

The Watershed Transform: De nitions, Algorithms and
Parallelization Strategies
Jos B.T.M. Roerdink and Arnold Meijster
Institute for Mathematics and Computing Science
University of Groningen
P.O. Box 800, 9700 AV Groningen, The Netherlands
Email: roe@cs.rug.nl,a.meijster@rc.rug.nl

2011년 9월 15일 목요일

Debian Wheezy의 safe-upgrade 해제한 최신 업데이트

다른건 아무런 문제가 없지만 gnome-terminal과 xterm등등의 gnome 어플리케이션의 동작에 문제가 생겼다. 아무래도 gnome버전이 2.x에서 3.0.1로 옮아가는 가정에서 생기는 문제점인거 같다. 일명 slow key라고 하는 한 5번 누르면 하나 입력이 되는 키보드 먹통현상이 가장 큰 문제이다. 그리고 gnome의 기본 테마가 적용이 안된다. xorg에서 제공하는 기본 테마가 적용되서 다른 어플리케이션과 스크롤바와 메뉴등의 테마가 다르다. 수정되겠지 하면서 쓰고 있다. 그냥 safe-upgrade로 업테이트 해야 겠다. 빨리 gnome 3.x가 안정화 되길 바란다.

여러가지 씨름을 한후 ibus와 scim의 충돌로 인한 키보드 입력에 문제가 발생한 것을 알아 차리고 scim을 지웠다. 그 이후로는 ibus를 입력기로 사용하고 있다. 키보드 입력문제는 해결을 보았으나, 여전히 테마적용문제는 풀리지 않고 있다.

이 문제도 해결을 보았다. home 디렉토리 밑의 .gconf를 싹 지웠더니 설정이 제대로 되고 있다. 하지만 그동안의 설정이 사라졌다.

2011년 9월 13일 화요일

멋있는 방문자 지도 제공 사이트

http://www.revolvermaps.com/?target=setup

지도와 해상도 기타등등을 선택하고 코드를 자신의 사이트에 추가하면 된다. 간단하다.

이러한 노력의 결과물을 많이 꽁짜로 제공하는데 왜 그런지 의문스럽다.

2011년 9월 11일 일요일

KS 규격 나사산 그리기(탭 깊이, 나사 맞춤 깊이)



* M3 x 0.5

숫나사의 바깥 지름 d: 3mm
나사를 내기 위한 구멍의 지름 d1: 2.4mm
드릴 깊이 b: 6(강, 주강, 청동, 청동주물), 7.5(주철), 8.5(알미늄과 기타의 경합금제)
탭 깊이 a: 3(강, 주강, 청동, 청동주물), 4.5(주철), 5.5(알미늄가 기타의 경합금제)

* M6 x 1

숫나사의 바깥 지름 d: 6mm
나사를 내기 위한 구멍의 지름 d1: 5mm
드릴 깊이 b: 10(강, 주강, 청동, 청동주물), 13(주철), 15(알미늄과 기타의 경합금제)
탭 깊이 a: 6(강, 주강, 청동, 청동주물), 9(주철), 11(알미늄가 기타의 경합금제)

2011년 9월 6일 화요일

Untouchable HDD noise on Laptop as having age.

I give a priority to change HDD as SDD for out of noise.

But my debian system is too heavy to reconfigure.

One of the disk copy between HDD is through "cat" commnand.

# cat /dev/sda1 > /dev/sda2

or

# dd if=/dev/sda1 of=backup , dd if=backup of=/dev/sda2

Other is backup image of HDD through "tar".

# cd /
# tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/media --exclude=/sys /

Then copy this tar into new HDD and extract it.

# cd $(new_HDD)
# tar xvpjf backup.tar.bz2 -C /
# mkdir proc
# mkdir lost+found
# mkdir mnt
# mkdir sys
# mkdir media

2011년 9월 5일 월요일

3x3 bitmask list sorted by crossing number and pixel count

Here is the source code for generating 3x3 bitmask list.

#include

int value_3x3[256][9+2];

int main(int argc, char *argv[])
{
int i, j, value;
int crossing = 0, count = 0;

for (i = 0; i < 256; i++) {
value_3x3[i][0] = '*';
for (j = 0; j < 8; j++) {
if (i & (1 << j)) value_3x3[i][j+1] = '*';
else value_3x3[i][j+1] = '=';
}
crossing = 0;
count = 0;
value = value_3x3[i][8];
for (j = 1; j <= 8; j++) {
if (value_3x3[i][j] != value) crossing++;
if (value_3x3[i][j] == value_3x3[i][0]) count++;
value = value_3x3[i][j];
}
value_3x3[i][9] = crossing;
value_3x3[i][10] = count;


}
for (crossing = 0; crossing <= 8; crossing += 2) {
for (count = 0; count <= 8; count++) {
for (i = 0; i < 256; i++) {
if (value_3x3[i][9] == crossing && value_3x3[i][10] == count) {
printf("%c%c%c\n", value_3x3[i][4], value_3x3[i][3], value_3x3[i][2]);
printf("%c%c%c %d %d\n", value_3x3[i][5], value_3x3[i][0], value_3x3[i][1], value_3x3[i][9], value_3x3[i][10]);
printf("%c%c%c\n", value_3x3[i][6], value_3x3[i][7], value_3x3[i][8]);
printf("\n");
}
}
}
}
return 0;
}

And then the sorted list is here.


3x3 bitmask, crossing number, pixels equal to center
-------------------------------------------------------------------------

2011년 9월 2일 금요일

To remove clicking configuration of hdparm in Asus 1215t debian system

1. edit /etc/hdparm.conf

...

/dev/sda
{
   apm = 255
   spindown_time = 0
       dma = on
}
...


2. edit /etc/apm/event.d/20hdparm

...
APMD_DRIVES=sda
...

power_performance ()
{
    # Disable IDE hard disk spindown.
    for DRIVE in $APMD_DRIVES; do
      "${HDPARM}" -q -S 0 -B 254 "${DRIVE}" || true
    done
}
...

3. edit /etc/acpi/fglrx-powermode.sh

...
for dev in /dev/sd? /dev/hd? ; do
   if [ -b $dev] ; then

      # Check for APM support; discard errors since not all drives
      # support HDIO_GET_IDENTITY (-i).
      if /sbin/hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes' ; then
        if [ -f /sys/class/power_supply/AC0/online ] && [ grep -q '1' /sys/class/power_supply/AC0/online ]; then
          /sbin/hdparm -B 254 $dev
        else
          /sbin/hdparm -B 128 $dev
        fi
      fi
   fi
done
...

[번역] hdparm - 완벽 가이드 (hdparm - complete guide)

출처 : http://forums.debian.net/viewtopic.php?t=32794


이글의 목적은 당신의 하드 디스크의 load cycle(하드 디스크의
clicking 음이 반복되어 나타나게 되는 원인)을 조절하기 위한 매개변수를 설정하는 것이다. 이를 통해서 laptop이나 desktop에서 불필요한 하드의 헤드의 정차(하드 디스크의 끍는 소리는 이 헤드의 정차음이다)를 멈출 수 있다.  그러나 이렇게 설정하더라도 베터리로 동작할때 laptop이 헤드의 정차를 하도록 한다.

그레서 나는 사람들이 작성한 스크립트를 이용한 방법을 전혀 사용하지 않았다. 여러분은 이 화면에 있는 것들을 복사해서 사용해야 할 것이다. 대신 약 1년쯤 전에 여러분이 지지하는 방식의 방법을 찾았다. 나는 항상 모두 공유하고 싶지만 워낙에 게을러서. 지금은 작업을 밀어붙이고 있으며 진작에 이것을 공유하지 않은 것에 대해서 자책하고 있다. 나는 여러분이 이 방법을 온라인상에서 찾아 볼 수 있을지 어떨지는 잘 모르겠다. howto 문서와 떨어져 있기 때문에 그러나 여러분은 검색을 통해서 찾아 볼 수 있다.

그리고 문서 작성하면서 기억해 낸 것인데 한가지 주의할 점은 255의 apm 순위는 어떤 컴퓨터에서는 작동하지 않는다. 여러분이 이 값으로 254를 사용하지 않는다면 모든 것은 기본적으로 동일하다.

1. 여러분은 repos(패키지 저장소)로 부터 구할 수 있는 hdparm, sysvconfg, smartmontools를 설치해야한다.

2. hdparm 이 로그인시 시작되는지 확인하자. sysvconfg를 실행하고 hdparm을 enable시키면 로그인시 자동으로 시작된다.

3. 그럼 여기서 내가 다르게 접근한 약간의 것들이 필요하다. 여러분이 직접 수정해야할 몇개의 파일들이 있다. 로그인시 로드되거나 이미 존재하는 hdparm의 config 파일과 약간의 스크립트가 필요하다. 그래서 여러분은 정확한 정보를 그들에게 알려주어야한다.

3.1. /etc/hdparm.conf 수정

...

/dev/${your hard drive name}
{
   apm = 254
   spindown_time = 0
   dma = on
}
...

3.2. 기타 파일 작성


# cd /etc/apm/event.d
# ls
# nano 20hdparm

그저 간단하다. 다음 몇 줄을 추가하자.

APMD_DRIVES=sda        ##Again put YOUR device

그런 다음 스크립트가 동작하도록 편집하자.

power_performance ()
{
    # Disable IDE hard disk spindown.
    for DRIVE in $APMD_DRIVES; do
      "${HDPARM}" -q -S 0 -B 255 "${DRIVE}" || true
    done
}

기본적으로 여러분은 AC 전원일때 loading/unloading cycles을 얻을 수 없다.

3.3. 마지막 단계.

ACPI 전원 관리를 위한 것이다.

# cd /etc/acpi/ac.d
# ls
# nano 90-hdparm.sh        ## or whatever ls shows you

...

for dev in /dev/sd? /dev/hd? ; do
    if [ -b $dev ] ; then
      # Check for APM support; discard errors since not all drives
      # support HDIO_GET_IDENTITY (-i).
      if hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes' ; then
        if [ $STATE = "BATTERY" ] ; then
          hdparm -B 128 $dev
        else
          hdparm -B 255 $dev
        fi
      fi
    fi
  done
fi
...

3.4. reboot후 확인하기

# smartctl -a /dev/sda | grep Load_Cycle_Count
# smartctl -a -d ata -i /dev/sda | grep Load_Cycle_Count

이 명령은 94116이라는 다섯 자리의 숫자를 제공할 것이다. 몇 분후에 다시 해보자. 숫자는 같아야 한다. 

그리고 몇일 후에 알아낸 것인데 내 컴퓨터의 경우 hdparm이 suspend후 resume되었을대 작동되지 않는다. 이경우 나는 다음과 같이 수동으로 사용한다.

# hdparm -B 254 -S 0 /dev/sda