1
$\begingroup$

This post is only a part of a broader analysis that I am performing on the image processing speed, but I think it's interesting in itself. I will post more in the next days. Now the problem is: I have a lot of images like this one

enter image description here

and I want straighten each of them. Obiously the rotation angle is not the same for all picture. To choose the correct one I have tried this:

numberFormat[arg_] := NumberForm[arg, {3, 3}, NumberSigns -> {"+", "-"}];
file = "c:\\degiorgi\\002\\z001.bmp";
img = Import[file, "BMP"];
Manipulate[
 ImageRotate[img, -t],
  Control[{{t, 0, Dynamic[numberFormat[t]]}, 0, 1, .1, 
  ControlType -> Slider}]
 ]

enter image description here

It works fine on little test images but grows deadly slow as image size increases and even to move the slider become practically impossibile. The same holds for

file = "c:\\degiorgi\\002\\z001.bmp";
img = Import[file, "BMP"];
r = Table[a, {a, 0, .5, .001}];
Manipulate[
 ImageRotate[img, -t]
 , Control[{t, r, ControlType -> PopupMenu}]
 ]

enter image description here

What am I doing wrong ? I think that all this is not affected by the machine performance because other image processing software, and vector drawing also, run fast.

In this specific case a possible workaround could be to process only the upper part of the image, but the main problem endures.

$\endgroup$
  • 2
    $\begingroup$ Look this $\endgroup$ – yode Mar 28 '16 at 8:59
3
$\begingroup$

The issue is that you are rotating the full resolution Image at every "step". You can manipulate a thumbnail and apply the transformation to the full image afterwards.

numberFormat[arg_] :=  NumberForm[arg, {3, 3}, NumberSigns -> {"+", "-"}];

(* Get the full image *)
file = "http://i.stack.imgur.com/rYS4s.jpg";
img = Import[file];

(* Resize to 250 pixels*)
tmb = Thumbnail[img, 250];

 Manipulate[
  Column[
   {ImageRotate[tmb,-t], 
    Button["Save",Print[ImageRotate[img,-t]]]}
  ],
  Control[{{t,0,Dynamic[numberFormat[t]]},0,1,.1,ControlType->Slider}]
 ]

Manipulate result

$\endgroup$
  • $\begingroup$ Your hint fully solves my problem, thanks ! When are involved colorful images may be useful to compose Binarize and Thumbnail. I'm going to try. $\endgroup$ – mitochondrial Mar 28 '16 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.