This implements the rotation part. Still pondering which is the better way to implement the interface for multiple transformations:
perComponentTransform[img_Image] :=
Module[{mc, m, col, colRuls, centerRuls, maskDataRuls, mask},
mc = MorphologicalComponents[img];
m = Max@mc;
col = Colorize[mc, ColorFunction -> "Rainbow"];
colRuls = Union@Flatten[MapThread[Rule, {mc, ImageData@col}, 2], 1];
{centerRuls, maskDataRuls} =
Transpose[Thread /@ ComponentMeasurements[img, {"Centroid", "Mask"}]];
mask = maskDataRuls /. (n_ -> a_SparseArray) :>
ColorReplace[Image@a, White -> RGBColor @@ (n /. colRuls)];
DynamicModule[{maskd = mask, k = 0, angle = Array[0 &, m], angleResv = Array[0 &, m]},
Panel@Dynamic@
Column[{
Row[{Image[col, ImageSize -> 200],
Column[
Table[With[{i = j},
DynamicModule[{y = angleResv[[i]]},
Row@{
Graphics[{RGBColor @@ (i /. colRuls), Rectangle[]}, ImageSize -> 15],
Slider[Dynamic[y, (k = i; angle[[i]] = y = #) &], {0, 2 Pi}],
Dynamic[y]}]], {j, m}]]}],
If[! $ControlActiveSetting && k != 0,
maskd[[k]] = ImageTransformation[mask[[k]],
RotationTransform[-angle[[k]], k /. centerRuls],
DataRange -> Full];
angleResv = angle; k = 0];
Image[Fold[ImageAdd, maskd], ImageSize -> 400]}]]]
Usage:
img = Binarize@Import@"https://i.sstatic.net/4SYJS.png";
perComponentTransform[img]
Due credit to Algohi for solving a nasty problem with ControlActive
for arrays of controls