How to implement custom data generator for images in keras? - image

I have used Keras generators through ImageDataGenerator, however I would like to extend it to include some transformations that are currently not included (say Gaussian smoothing). For example,
datagen = ImageDataGenerator(
rotation_range = 5,
width_shift_range = 0.1,
my_smoothing_kernel = 0.3)
where obviously my_smoothing_kernel would be the function I would like to add. Does anyone have any idea how to do this? I would then like to use datagan.flow as an input into model.fit as normal. Any help would be greatly appreciated.

Related

How can I determine the values shown on a spectrograph colorbar?

I am trying to make sure that a bunch of different spectrographs I am trying to produce have the same colorbar scale so I can compare them. This is the code I have so far:
for tr in traces:
#fig = tr.spectrogram(log=True)
fig = tr.spectrogram(show=False, log=True)
ax = fig.axes[0]
mappable = ax.collections[0]
plt.colorbar(mappable=mappable, ax=ax)
plt.show()
This is a sample spectrograph I produced with that:
If I wanted the colorbar range to go from 0 to 800 rather than 0 to 120, how could I do that? Thank you.
I've so far looked at the documentation for matplotlib.pyplot.colorbar, but I cannot see if there's a way to do what I am trying.

Issues with placementTransform Matrix when loading multiple models to Autodesk Forge

When loading multiple models, I am using the placementTransform parameters.
the issues I am facing is that the Rotation works however the translation does not.
var Rmat = new THREE.Matrix4();
Tmat=new THREE.Matrix4().makeTranslation(X,Y,Z);
Rmat.makeRotationZ(Angle);
Rmat.multiply(Tmat);
var modelOptions = {
placementTransform: Rmat,
sharedPropertyDbPath: doc.getRoot().getPropertyDbManifest()
};
As far as I know, placementTransform should support both translation and rotation. Try applying the transformations individually (only translation or only rotation), see if both are applied as expected. And also double-check if you're multiplying the matrices in the correct order.
Moreover, if you can reproduce the issue in a sample app, please share it with us via forge (dot) help (at) autodesk (dot) com and we'll take a look at it.
I tried all the combinations the only one that worked was using the globalOffset
and commented this._firstGlobalOffset the code that worked is as follows:
//this._firstGlobalOffset = {x:0,y:0,z:0}; // Commented
var Rmat = new THREE.Matrix4();
Rmat.makeRotationZ(Angle);
var modelOptions = {
placementTransform: Rmat,
globalOffset:{x:X,y:X,z:Z},
sharedPropertyDbPath: doc.getRoot().getPropertyDbManifest()
};

How to implement a morphtargets human demo use gltf?

Just like https://threejs.org/examples/?q=morph#webgl_morphtargets_human,
but I want to implement a glTF based demo .
I had tried glTF models such as https://github.com/HowardWolosky/glTF-Sample-Models/tree/morphAnimation/2.0/AnimatedMorphCube and https://github.com/HowardWolosky/glTF-Sample-Models/tree/morphAnimation/2.0/AnimatedMorphSphere, but they use animations, I want to control the morph weights manually, like:
mesh.morphTargetInfluences[0] = 0.5;
mesh.morphTargetInfluences[1] = 0;
mesh.morphTargetInfluences[2] = 1;
Thanks
I had solve this question myself by changing code in gltfloader.js.
see https://github.com/mrdoob/three.js/pull/11786#issuecomment-316423788

Add mean and variability to seaborn FacetGrid distplots

What is the best way to add a point representing the mean (or another measure of central tendency) and a measure of variability (e.g., standard deviation or confidence interval) to each histogram in a seaborn FacetGrid?
The result should look similar to the figure shown here, but with a mean/SD in each of the FacetGrid subplots. This is a related question for the non-FacetGrid case.
Based on #mwaskom's comment, here is one possible solution (using boxplot, analogous for pointplot):
tips = sns.load_dataset("tips")
sns.set(font_scale=1.3)
def dist_boxplot(x, **kwargs):
ax = sns.distplot(x, hist_kws=dict(alpha=0.2))
ax2 = ax.twinx()
sns.boxplot(x=x, ax=ax2)
ax2.set(ylim=(-5, 5))
g = sns.FacetGrid(tips, col="sex")
g.map(dist_boxplot, "total_bill");
(Not sure why the 0.01 is shifted slightly rightwards...)

Python regionprops sci-kit image

I am using sci-kit image to get the "regionprops" of a segmented image. I then wish to replace each of the segment labels with their corresponding statistic (e.g eccentricity).
from skimage import segmentation
from skimage.measure import regionprops
#a segmented image
labels = segmentation.slic(img1, compactness=10, n_segments=200)
propimage = labels
#props loop
for region in regionprops(labels1, properties ='eccentricity') :
eccentricity = region.eccentricity
propimage[propimage==region] = eccentricity
This runs, but the propimage values do not change from their original labels
I have also tried:
for i in range(0,max(labels)):
prop = regions[i].eccentricity #the way to cal a single prop
propimage[i]= prop
This delivers this error
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I am a recent migrant from matlab where I have implemented this, but the data structures used are completely different.
Can any one help me with this?
Thanks
Use ndimage from scipy : the sum() function can operate using your label array.
from scipy import ndimage as nd
sizes = nd.sum(label_file[0]>0, labels=label_file[0], index=np.arange(0,label_file[1])
You can then evaluate the distribution with numpy.histogram and so on.

Resources