after generating images from microsoft glee graph is there anyway to get the inputs to an image map - graphing

i am taking microsoft glee code and producing a graph and then converting it to an image on an html page. i want to see if i can autogenerate image map code over the image so i am able to click on each element of the graph nodes.
Here is an example of the glee graph code converting to an image.
Graph g = new Graph("graph");
g.GraphAttr.LayerDirection = LayerDirection.LR;
g.GraphAttr.NodeAttr.Padding = 3;
[Add a bunch of nodes . . .]
GraphRenderer renderer = new GraphRenderer(g);
renderer.CalculateLayout();
//Bitmap bmp = new Bitmap(Convert.ToInt32(g.Width), Convert.ToInt32(g.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Bitmap bmp = new Bitmap(Convert.ToInt32(g.Width), Convert.ToInt32(g.Height),
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
renderer.Render(bmp);
So the question is: is there a way to get all of the info that would be needed for an html image map from the glee graph object or the renderer.

Have a look at Mindscape's WPF Star Diagrams or WPF Flow Diagrams. They make this task much simpler and they look great!

Related

How to resize a nifti (nii.gz medical image) file

I have some medical images of nii.gz format which are of different shapes. I want to resize all to the same shape inorder to feed to a deep learnig model, I tried using resample_img() of nibabel, but it destroys my images. I want to do some other function just to resize it to a particular shape, say (512,512,129).
Someone please help me in this regard. I am stuck in this step for quite a good number of days.
Maybe you can use this:
https://scikit-image.org/docs/dev/api/skimage.transform.html
I saw it in one of the papers. Here is the example in function ScaleToFixed:
https://github.com/sacmehta/3D-ESPNet/blob/master/Transforms.py
Here is how I did it. I have the volume of shape 320x320x130 (black and white so no rgb dimension). I want to make it twice as small. This worked for me:
import skimage.transform as skTrans
im = nib.load(file_path).get_fdata()
result1 = skTrans.resize(im, (160,160,130), order=1, preserve_range=True)
You can use TorchIO:
import torchio as tio
image = tio.ScalarImage('path/to/image.nii.gz')
transform = tio.CropOrPad((512,512,129))
output = transform(image)
If you would like to keep the original field of view, you could use the Resample transform instead.
Disclaimer: I'm the main developer of TorchIO.

Can YOLO pictures have a bounded box that covering the whole picture?

I wonder why YOLO pictures need to have a bounding box.
Assume that we are using Darknet. Each image need to have a corresponding .txt file with the same name as the image file. Inside the .txt file it need to be. It's the same for all YOLO frameworks that are using bounded boxes for labeling.
<object-class> <x> <y> <width> <height>
Where x, y, width, and height are relative to the image's width and height.
For exampel. If we goto this page and press YOLO Darknet TXT button and download the .zip file and then go to train folder. Then we can see a these files
IMG_0074_jpg.rf.64efe06bcd723dc66b0d071bfb47948a.jpg
IMG_0074_jpg.rf.64efe06bcd723dc66b0d071bfb47948a.txt
Where the .txt file looks like this
0 0.7055288461538461 0.6538461538461539 0.11658653846153846 0.4110576923076923
1 0.5913461538461539 0.3545673076923077 0.17307692307692307 0.6538461538461539
Every image has the size 416x416. This image looks like this:
My idéa is that every image should have one class. Only one class. And the image should taked with a camera like this.
This camera snap should been taked as:
Take camera snap
Cut the camera snap into desired size
Upscale it to square 416x416
Like this:
And then every .txt file that correspons for every image should look like this:
<object-class> 0 0 1 1
Question
Is this possible for e.g Darknet or other framework that are using bounded boxes to labeling the classes?
Instead of let the software e.g Darknet upscale the bounded boxes to 416x416 for every class object, then I should do it and change the .txt file to x = 0, y = 0, width = 1, height = 1 for every image that only having one class object.
Is that possible for me to create a traing set in that way and train with it?
Little disclaimer I have to say that I am not an expert on this, I am part of a project and we are using darknet so I had some time experimenting.
So if I understand it right you want to train with cropped single class images with full image sized bounding boxes.
It is possible to do it and I am using something like that but it is most likely not what you want.
Let me tell you about the problems and unexpected behaviour this method creates.
When you train with images that has full image size bounding boxes yolo can not make proper detection because while training it also learns the backgrounds and empty spaces of your dataset. More specifically objects on your training dataset has to be in the same context as your real life usage. If you train it with dog images on the jungle it won't do a good job of predicting dogs in house.
If you are only going to use it with classification you can still train it like this it still classifies fine but images that you are going to predict also should be like your training dataset, so by looking at your example if you train images like this cropped dog picture your model won't be able to classify the dog on the first image.
For a better example, in my case detection wasn't required. I am working with food images and I only predict the meal on the plate, so I trained with full image sized bboxes since every food has one class. It perfectly classifies the food but the bboxes are always predicted as full image.
So my understanding for the theory part of this, if you feed the network with only full image bboxes it learns that making the box as big as possible is results in less error rate so it optimizes that way, this is kind of wasting half of the algorithm but it works for me.
Also your images don't need to be 416x416 it resizes to that whatever size you give it, you can also change it from cfg file.
I have a code that makes full sized bboxes for all images in a directory if you want to try it fast.(It overrides existing annotations so be careful)
Finally boxes should be like this for them to be centered full size, x and y are center of the bbox it should be center/half of the image.
<object-class> 0.5 0.5 1 1
from imagepreprocessing.darknet_functions import create_training_data_yolo, auto_annotation_by_random_points
import os
main_dir = "datasets/my_dataset"
# auto annotating all images by their center points (x,y,w,h)
folders = sorted(os.listdir(main_dir))
for index, folder in enumerate(folders):
auto_annotation_by_random_points(os.path.join(main_dir, folder), index, annotation_points=((0.5,0.5), (0.5,0.5), (1.0,1.0), (1.0,1.0)))
# creating required files
create_training_data_yolo(main_dir)
```

Using machine learning to remove background in image of hand-written signature

I am new to machine learning.
I want to prepare a document with a signature at the bottom of it.
For this purpose I am taking a photo of the user's signature for placement in the document.
How can I using machine learning extract only the signature part from the image and place it on the document?
Input example:
Output expected in gif format:
Extract the green image plane. Then take the complementary of the gray value of every pixel as the transparency coefficient. Then you can perform compositing to the destination.
https://en.wikipedia.org/wiki/Alpha_compositing
A simple image-processing technique using OpenCV should work. The idea is to obtain a binary image then bitwise-and the image to remove the non-signature details. Here's the results:
Input image
Binary image
Result
Code
import cv2
# Load image, convert to grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Bitwise-and and color background white
result = cv2.bitwise_and(image, image, mask=thresh)
result[thresh==0] = [255,255,255]
cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()
Please do research before posting questions like these. A simple google search of "extract signature from image python" gave so many results.
Git Repo
Git Repo
Stack Overflow
There are many other such alternatives. Please have a look and try a few approaches.
If you still have some questions or doubts, then post the approach you have taken and a discussion is warranted.

Get face coordinates using affdex sdk

It's possible to get face coordinates in image source file or frame? Some thing like:
face.Height = Affdex.Face[0].PositionHeight;
face.Left = Affdex.Face[0].PositionLeft;
face.Top = Affdex.Face[0].PositionTop;
face.Width = Affdex.Face[0].PositionWidth;
http://developer.affectiva.com/fpi/
The bounding box for each face is not provided directly via the Affdex SDKs, but they do provide coordinates for all the face points, so to determine a face's bounding box, all you need to do is iterate through its face points and track the max/min values in each dimension.
As an example, see the drawFacePoints method in the DrawingView class of the AffdexMe sample app: https://github.com/Affectiva/affdexme-android/blob/master/app/src/main/java/com/affectiva/affdexme/DrawingView.java

How can I crop by x,y,width,height all images in a folder, resize them, then save them?

I am new to Photoshop scripting, but no stranger to Javascript.
I have a folder of images of 1024*1024 that are frames of an animation in a 3d program.
There is only an area at x=54, y=12, width=300, height=234 for all the frames.
After the crop I would like them to be scaled at 65% or whatever I want.
Alternatively I would like the source image to be scaled, the image moved x / y coordinates at 65% reduction so that the outside pixels don't make it in the final product.
There are no psds to speak of, I assume the script would create a blank psd and most likely have it recycled for the batch crop/resize.
Try something along these lines for the cropping and resizing. You can also copy all the images into a single PSD before you save if that is what you're after, but this sample just saves over the original document. For more info check out your Photoshop JavaScript Reference pdf in your Photoshop install directory.
var dir = new Folder('/c/temp')
var files = dir.getFiles("*.psd"); //change for whatever file type you have
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
var bounds = [54, 12, 354, 246];
doc.crop(bounds);
//do the math to figure out how big you want it after resize
doc.resizeImage(newWidth, newHeight);
//note this is saving over the original!!!!
doc.close(SaveOptions.SAVECHANGES)
}
why not just record the action in photoshop???
open the first file and create a new action.
proceed to trim the canvas as needed with either the crop tool or canvas resize.
run the action as a batch process on the folder as needed.