I have both an image and a linear scale that I need to zoom in/out.
I have done this by getting the Y domain of the zoom transform and successfully zooming both that way:
y.domain(zoomTransform.rescaleY(y).domain());
But is it possible to do the reverse? Set the zoomTransform.k and zoomTransform.y values based on the Y domain of the scale? And in that way allowing the user to specifically setting the zoom-domain?
I ended up creating loops to gently modify the zoomTransform.y and k values and then fetching y.invert(0) and y.invert(height) values to check if the result was closer to the wanted range on every iteration. Had to put a another loop on top of these as changing the y affects the k and changing the k affects the y...
Not very pretty but seems to do the job.
Related
I have an array of pixel data taken from a Texture2D (512 x 512) within Unity.
Currently, I'm adding a border around this texture by using a for loop and setting the outer pixels to Color.black.
But some Texture2Ds are actually circular (in terms of the image/photo itself). And I would like to add a circular border around these images.
The typical for-loops (r++ & c++) gives a linear (bottom left, to top right) value, which wont work for a circle, right? Is there some kind of algorithm I can use to make the for-loop circular (in terms of the r and c values)?
Does this make any sense?
Thanks.
Funny question :)
I can't think of a solution to make for-loop 'circular', becouse x and y depend on each other and simple x++ y++ is not possible.
A simple solution is to calculate x and y inside some loop. Like using x = r*cos(t); y = r*sin(t); and iterating over t
I made a fiddle, it draws circle on html canvas using for-loop :D
Depending on what you want the end result to look like, you might be better off modifying via a shader to do a form of edge detection (it does depend on what you're texture is though).
Another, possibly easier solution is just to layer a second texture on top of your original where the second is just the border with the rest alpha'd out.
I am want to draw once, and then update (very) often and redraw (less) often an image in MATLAB. My image is a vector which is updated and redrawn. To show this image, I used I = imagesc(reshape(data, nVoxels)) to draw and I.CData(:) = data to update. (Redrawing is taken care of seperately.) This worked fine.
Now, in order to make the correspondence to an x-y-coordinate system (x horizontal, y vertical - very standard), where the first dimension of reshape(data, nVoxels) is x and the second is y, I need to draw like this:
I = imagesc(reshape(data, nVoxels)');
axis('xy');
But how can I make a quick update of the image data now?
So far, I have found I need to do
I.CData = reshape(data, nVoxels)';
but I would prefer to do something like before, updating CData without having to reallocate and without having to transpose the data.
Is that possible? I am specifically interested in updating very often in a loop; redrawing is handled independently using a timer.
The transpose can be avoided by setting x and y limits when you create the image to flip it, and rotating the axes:
I = imagesc([nVoxels(2) 1], [1 nVoxels(1)], reshape(data, nVoxels));
camroll(90);
then using
I.CData(:) = data;
again.
However, the transpose time is probably negligible compared to updating the figure using drawnow().
I have a program where I have a slider, and when i move it up or down (left or right) the color changes gradually. Sadly I am not able to achieve this. My colors change yes, but it is very sudden! I have the 7 colors of the rainbow on seperate .png files and when I scroll the respective one comes up. I was wondering if there was anything I could do to make the colors morph or blend into each other better to make the transaction appear muuch more smoothly.
Thank you
UPDATE
if(self.slider.value > 7 (
{
self.label.text=#"red";
//self.imgView.backgroundColor=[UIColor redColor];
// self.imgView.backgroundColor=[UIColor colorWithPatternImage:#"redPicture"];
self.view.backgroundColor=[UIColor colorWithRed:146 green:50 blue:146 alpha:1];
}
This is going to be a generalized answer because I'm not going to write your code for you (not least because I have never written a letter of xcode in my life), but this should put you on the right track.
You want a continuous spectrum of color, so that should tell you right off the bat that using a series of if statements is the wrong way to go. Instead, you should calculate the color you want by doing some math with the slider value directly.
You haven't told me what your slider range is and whether it's discrete, so for the purposes of this answer let's call the lowest value min and the highest value max, just to keep things general. So your total range is max - min. Let's express the value of your slider as a percentage along this range; we can calculate this as (self.slider.value - min) / (max - min). (For instance, for a slider that goes from 0 to 50, a slider value of 37 gives you (37-0)/(50-0) = 0.74.)
So now you should have a decimal value between 0 and 1, which you can map along the Hue-Saturation-Value color scale. I don't know if xcode has a HSV method directly (this answer has some code which might be helpful), but if not it's pretty easy to convert HSV to RGB.
I am trying to create a graph based on Mike Bostock's Heirarchical Edge Bundling(here is the gist). I need to make my JSON look as readme-flare-imports.json looks, but I can't figure out what "size" is. I read the API and it didn't seem to help me. Also, it will be a dynamic JSON file based on a mySQL database, so I won't be able to set the size myself. Is anybody able to clear things up for me as to what it is or how I may be able to determine what the size should be? Thank you in advance!
cluster.size determines how large of an area the cluster will take up. You pass values to it like so
// The angle
var x = 360;
// The radius
var y = window.height / 2;
cluster.size([x, y])
x will determine how much of a circle the cluster will use to branch out children. A value of 360 will use the entire circle to display all values. A value of 180 will only use half the circle to branch out values.
y will determine how wide the circle will become in any single direction, i.e., the radius of the circle.
In the Heirarchical Edge Bundling example, I believe the size attribute in the json file is ignored as I could not find anything in the code that cared about it.
I am developing an application to register and display a 3D DICOM image using VTK, ITK, and QT.
I am running into some issues with the registration part.
I am using the ScaleVersor3DTransform, VersorTransformOptimizer, NormalizedCorrelationImageToImageMetric, and LinearInterpolateImageFunction for this.
The problem is that I need to lock or disable the rotation on Z axis. The only axis that can rotate are X and Y.
I tried getting the GetNumberOfParameters() from the transform and setting all its values to 1.0 (although I think the Z-rotation is the third position on the array), but that didn't seen to work.
What are my options?
You can minimize (or disable) a certain parameter by setting a very high scale for the parameter you do not want to optimize (using SetScales on the optimizer). In the case of a ScaleVersor3DTransform, no single parameter is representing the Z-rotation, so I am afraid it won't work out for your specific case.
You could consider to use a Euler3DTransform instead, for which the Z-rotation is a specific parameter of the transformation.