question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow controlling intensity of RandomMotion transform

See original GitHub issue

🚀 Feature

Motivation

Intensity of RandomMotion transform seems to mostly depend on the “time” of the motion. And while RandomGhosting transform exposes intensity parameter, RandomMotion does not expose times parameter, and does not have intensity.

Pitch

Either provide intensity parameter, or allow setting the range of times parameter used internally.

Alternatives

Save the image before the transform is applied, then “manually” blend the transformed one into the original one with custom weight, thus emulating intensity.

Additional context

I am trying to augment training by creating bad images for an image quality estimator, because most images in my training set are good. I would like to control the degree of corruption, e.g. to have control whether I produce an image with rating of 1/10 or 4/10.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
fepegarcommented, Dec 2, 2021

I coded this transform a long time ago reading Richard Shaw’s paper. My version is a bit simplified, but works. I am now away at a conference, but I’ll try to add some explanations to the docs when I’m back.

For now, maybe you can just use a convex combination of the original image and the transformed one:

import torch
import torchio as tio


class MyRandomMotion(tio.RandomMotion):
    def __init__(self, *, intensity, **kwargs):
        self.intensity = intensity
        super().__init__(**kwargs)

    def apply_transform(self, subject):
        transformed = super().apply_transform(subject)
        for image_name in self.get_images_dict(subject):
            original = subject[image_name]
            new = transformed[image_name]
            alpha = self.intensity
            composite_data = new.data * alpha + original.data * (1 - alpha)
            transformed[image_name].set_data(composite_data)
        return transformed


fpg = tio.datasets.FPG()
seed = 42

transform = MyRandomMotion(intensity=0)
torch.manual_seed(seed)
transform(fpg).t1.plot()

transform = MyRandomMotion(intensity=1)
torch.manual_seed(seed)
transform(fpg).t1.plot()

Figure_1

Figure_2

0reactions
fepegarcommented, Dec 7, 2021

@fepegar would it be easy to add Motion transform in the Slicer pluggin ? (this would answer the initial need of exploration) and more generally it may be interesting for other transform too (ie not the Radom version)

It would be easy, yes. But it would take a bit of time, which I don’t really have now. Feel free to open a PR!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use the Random Expression in After Effects
Take control of randomly animated movements. Here's how to use the random expression in After Effects.
Read more >
Cinema 4D Tutorial - Controlling Light Intensity With Effectors
... explain a couple very simple ways that you can effect Light Objects intensity in Cinema 4D with effectors and how to get...
Read more >
3D Light controls in Motion - Apple Support
In Motion, control lighting effects (ambience, intensity, direction, color, falloff, focus, ... The Light HUD also contains 3D transform controls.
Read more >
Motion intensity modeling and trajectory control of upper limb ...
The experimental results show that the proposed motion intensity perception model based on deep neural network (DNN) and the trajectory control ...
Read more >
Random Motion - MotionScript.com
The first block of code defines the parameters that control the structure of the grid and the speed of layer movement. "origin" is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found