Skip to content

Commit

Permalink
Add PixImage<T>.Transformed
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jun 24, 2024
1 parent e28203c commit c699bc6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 52 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `PixVolume` implements `IPixImage3d`
- Added `PixVolume.BytesPerChannel`
- Added `PixVolume.ToCanonicalDenseLayout`
- Added `Add PixImage<T>.Transformed` (abstract `PixImage.Transformed` is renamed to `PixImage.TransformedPixImage`)
- Removed obsolete loading API
- Removed obsolete API:
- [Color] obsolete conversion functions
Expand Down
78 changes: 27 additions & 51 deletions src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public PixImage<T> ToPixImage<T>(Col.Format format)

#region Image Manipulation

public abstract PixImage Transformed(ImageTrafo trafo);
public abstract PixImage TransformedPixImage(ImageTrafo trafo);

public abstract PixImage RemappedPixImage(Matrix<float> xMap, Matrix<float> yMap, ImageInterpolation ip = ImageInterpolation.Cubic);

Expand Down Expand Up @@ -1282,13 +1282,14 @@ public IEnumerable<Matrix<T>> Channels

#region Image Manipulation

public override PixImage Transformed(ImageTrafo trafo)
public override PixImage TransformedPixImage(ImageTrafo trafo)
=> Transformed(trafo);

public PixImage<T> Transformed(ImageTrafo trafo)
=> new PixImage<T>(Format, Volume.Transformed(trafo));

public override PixImage RemappedPixImage(
Matrix<float> xMap, Matrix<float> yMap,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Remapped(xMap, xMap, ip);
public override PixImage RemappedPixImage(Matrix<float> xMap, Matrix<float> yMap, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Remapped(xMap, xMap, ip);

public PixImage<T> Remapped(Matrix<float> xMap, Matrix<float> yMap, ImageInterpolation ip = ImageInterpolation.Cubic)
{
Expand All @@ -1302,32 +1303,20 @@ public PixImage<T> Remapped(Matrix<float> xMap, Matrix<float> yMap, ImageInterpo

private static Func<Volume<T>, Matrix<float>, Matrix<float>, ImageInterpolation, Volume<T>> s_remappedFun = null;

public static void SetRemappedFun(
Func<Volume<T>, Matrix<float>, Matrix<float>, ImageInterpolation, Volume<T>> remappedFun
)
{
s_remappedFun = remappedFun;
}
public static void SetRemappedFun(Func<Volume<T>, Matrix<float>, Matrix<float>, ImageInterpolation, Volume<T>> remappedFun)
=> s_remappedFun = remappedFun;

public override PixImage ResizedPixImage(
V2i newSize,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled((V2d)newSize / (V2d)Size, ip);
public override PixImage ResizedPixImage(V2i newSize, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled((V2d)newSize / (V2d)Size, ip);

public PixImage<T> Resized(
V2i newSize,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled((V2d)newSize / (V2d)Size, ip);
public PixImage<T> Resized(V2i newSize, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled((V2d)newSize / (V2d)Size, ip);

public PixImage<T> Resized(
int xSize, int ySize,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled(new V2d(xSize, ySize) / (V2d)Size, ip);
public PixImage<T> Resized(int xSize, int ySize, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled(new V2d(xSize, ySize) / (V2d)Size, ip);

public override PixImage RotatedPixImage(
double angleInRadiansCCW, bool resize = true,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Rotated(angleInRadiansCCW, resize, ip);
public override PixImage RotatedPixImage(double angleInRadiansCCW, bool resize = true, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Rotated(angleInRadiansCCW, resize, ip);

public PixImage<T> Rotated(double angleInRadiansCCW, bool resize = true, ImageInterpolation ip = ImageInterpolation.Cubic)
{
Expand All @@ -1341,20 +1330,13 @@ public PixImage<T> Rotated(double angleInRadiansCCW, bool resize = true, ImageIn

private static Func<Volume<T>, double, bool, ImageInterpolation, Volume<T>> s_rotatedFun = null;

public static void SetRotatedFun(
Func<Volume<T>, double, bool, ImageInterpolation, Volume<T>> rotatedFun)
{
s_rotatedFun = rotatedFun;
}
public static void SetRotatedFun(Func<Volume<T>, double, bool, ImageInterpolation, Volume<T>> rotatedFun)
=> s_rotatedFun = rotatedFun;

public override PixImage ScaledPixImage(
V2d scaleFactor,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled(scaleFactor, ip);
public override PixImage ScaledPixImage(V2d scaleFactor, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled(scaleFactor, ip);

public PixImage<T> Scaled(
V2d scaleFactor,
ImageInterpolation ip = ImageInterpolation.Cubic)
public PixImage<T> Scaled(V2d scaleFactor, ImageInterpolation ip = ImageInterpolation.Cubic)
{
if (s_scaledFun == null)
{
Expand All @@ -1373,19 +1355,13 @@ public PixImage<T> Scaled(
private static Func<Volume<T>, V2d, ImageInterpolation, Volume<T>> s_scaledFun = TensorExtensions.Scaled;

public static void SetScaledFun(Func<Volume<T>, V2d, ImageInterpolation, Volume<T>> scaledFun)
{
s_scaledFun = scaledFun;
}
=> s_scaledFun = scaledFun;

public PixImage<T> Scaled(
double scaleFactor,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled(new V2d(scaleFactor, scaleFactor), ip);
public PixImage<T> Scaled(double scaleFactor, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled(new V2d(scaleFactor, scaleFactor), ip);

public PixImage<T> Scaled(
double xScaleFactor, double yScaleFactor,
ImageInterpolation ip = ImageInterpolation.Cubic
) => Scaled(new V2d(xScaleFactor, yScaleFactor), ip);
public PixImage<T> Scaled(double xScaleFactor, double yScaleFactor, ImageInterpolation ip = ImageInterpolation.Cubic)
=> Scaled(new V2d(xScaleFactor, yScaleFactor), ip);

#endregion

Expand Down
2 changes: 1 addition & 1 deletion src/Aardvark.Base.Tensors/PixImage/PixImageCube.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module FSharpPixImageCubeExtensions =
|> Array.mapi (fun i mipMap ->
let side = unbox<CubeSide> i
let (newSide, trafo) = m side
newSide, PixImageMipMap (mipMap.ImageArray |> Array.map (fun pi -> pi.Transformed(trafo)))
newSide, PixImageMipMap (mipMap.ImageArray |> Array.map (fun pi -> pi.TransformedPixImage(trafo)))
)
|> Map.ofArray
|> Map.toArray
Expand Down

0 comments on commit c699bc6

Please sign in to comment.