Im currently trying to figure out how to get an individual pixel using the Node.js gm graphicsMagic wrapper. My overall end goal is to get the top 10 colors with percentages in an image. I am trying to write a few functions that will get me my result but for the life of me I can't figure out hwo to get the pixel itself using the gm wrapper. It seems that GraphicsMagick has a GetPixels method but I havent had luck being able to call it. Any help would be greatly appreciated.
Thanks!
I wanted to get the average color of an image and I solved it with the following script:
gm(file).setFormat('ppm')
.resize(1, 1)
.toBuffer(function (err, buffer) {
var color = "rgb(" + buffer.readUInt8(buffer.length - 3)
+ "," + buffer.readUInt8(buffer.length - 2)
+ "," + buffer.readUInt8(buffer.length - 1) + ")";
// ...
});
Basically, you could crop the image and convert it to the ppm format to read the pixels from the buffer. Not optimal at all and I really hope that there is a better solution, but for my case it was good enough.
Edit: Another option might be to use Custom Arguments.
Related
Hallo I am currently trying to build a tree in D3.js.
For this I donwloadet the repository of the mitch-tree:
https://github.com/deltoss/d3-mitch-tree
I wantet to ask, if maybe somebody already has expirience with this issue?
So, I build a tree with processcharts.
But I have the problem, that the text hast to fit the boxes right nor, or it will get cut out.
It would be great to be able to fit the boxes to the content, so making them resizeable or, maybe make the boxes collapsable..
Maybe somebody hast a tipp for me, how to reach that goal.
I think I found the part of the code where the cutting/ resizing might be happaning for my textBox.
But I am really not sure..
If I got it right, the textbox resizes already what is inside with this function and cuts the words, that are to much for my box are out:
// D3Plus Textbox with resizing capability
var d3PlusBodyTextBox = new d3PlusTextBox()
.select(element) // Sets the D3Plus code to append to the specified DOM element.
.data(singledOutData)
.text((data, index, arr) => {
return self.getBodyDisplayText.call(self, data);
})
.textAnchor("middle")
.verticalAlign("middle")
.fontSize(13) // in pixels
.x(nodeBodyBoxPadding.left)
.y(recalculatedPaddingTop - nodeBodyBoxHeight / 2)
.width(nodeBodyBoxWidth - nodeBodyBoxPadding.left - nodeBodyBoxPadding.right)
.height(nodeBodyBoxHeight - recalculatedPaddingTop - nodeBodyBoxPadding.bottom)
.ellipsis((text, line) => {
// If text was cut-off, add tooltip
selection.append("title")
.text(self.getBodyDisplayText(data));
return ((text.replace(/\.|,$/g, "")) + "...");
})
.render();
});
Has anyone maybe a tipp for me how to change it in a good and functional way?
Thanks in advance :)
I'm trying to overlay text on top of a GIF using the gm package. It does overlay the text on top of regular images, however on GIFs it just overlays the last 2 frames. I don't have much experience using this package and Imagemagick.
Here's the code that edits the image.
gm(request(image)) //any image url
.command('convert')
.coalesce()
.font("./impact.ttf")
.dither(false)
.fontSize(Math.round(width/11)) //Width is defined earlier in the code
.stroke("#000000")
.strokeWidth(width/450)
.out('-gravity', 'north')
.out('-size',width+'x','-fill','white','-background', 'transparent', '0')
.out('caption:' + meme[0].toUpperCase().substr(meme[0].indexOf(" ")+1))
.out('-layers','optimize')
.out('-gravity', 'south')
.out('-size',width+'x','caption:' + meme[1].toUpperCase())
.out('-layers','optimize')
.strip()
// If i use these two, it does append all the layers but the text does not wrap like it does using caption
// .drawText(0,1, meme[0].toUpperCase().substr(meme[0].indexOf(" ") + 1), 'North')
// .drawText(0,0, meme[1].toUpperCase(), 'South')
.stream((error, stdout) => {...}
Result of the code
Any help would be appreciated!
I have a problem I solved in Excel but I am completely stuck in Matlab.
A weight measuring how much liquid I pump is refilled when its almost empty. Here is a picture
Now I want to see it in one motion, not like a jigsaw. Here is my solution, doing it manually in Excel:
Now to Matlab where this should be done automatically: I know how to index the row before and after I have the bumps, but I'm kind of stuck now. I do d=diff(x) ok and now I can replace the high peaks when the bumps occur (i=d(:,1)>0) with 0 so it never happened. And how do I translate it back? Somehow "undiff(x)"? im completely lost.
Here's an extract of my x:
2533,30
3540,00
3484,90
3430,00
3375,00
3320,20
3265,60
3210,60
3155,80
3101,20
3046,50
2991,70
2937,00
2882,50
2828,10
2773,80
2719,30
2664,90
2610,50
2556,10
2501,60
3508,00
3454,00
3399,70
3352,10
Like this?
temp = [0; diff(x)];
temp(temp < 0) = 0;
y = x - cumsum(temp);
y(temp > 0) = interp1(y, find(temp > 0) + 0.5);
plot(y);
hen using the default plot() function, matlab will automatically draw a line plot and connect each point in the data you are plotting.
Instead it seems like you just need to plot the points individually and unconnected. So if you are currently doing something like plot(x) or area(x) instead try plot(x,'o'). This will cause Matlab to plot the points individually without connecting them as lines.
If you'd like to change the marker type used to plot each point, use doc linespec to get more info.
I'm trying to capture images within node.js from a webcam connected to a Raspberry Pi. Capturing works fine, but now when I want to transmit the images I have some serious problems with framerate and lags.
Now my first idea was to convert the RGB images to 8bit grayscale, that should increase the performance by factor 3 (i hope..).
I'm using node.js and opencv-node for this. Here you can see some code snippet for the moment:
var startT = new Date().getTime();
var capture = new cv.VideoCapture();
var frame = new cv.Mat;
var grey = new cv.Mat;
var imgPath = __dirname + "/ramdisk/";
var frame_number = 0;
capture.open(0);
if (!capture.isOpened())
{
console.log("aCapLive could not open capture!");
return;
}
function ImgCap()
{
var elapsed = (new Date().getTime() - startT) / 1000;
capture.read(frame);
cv.imwrite(imgPath+".bmp", frame);
id = setImmediate(ImgCap);
}
ImgCap();
I tried to use something like
cv.cvtColor(frame, grey, "CV_BGR2GRAY");
after reading the image but i only get some TypeError saying that argument 2 has to be an integer... I dont know what to do at the moment. I referred to http://docs.opencv.org/doc/tutorials/introduction/load_save_image/load_save_image.html#explanation for converting a rgb to a grayscale image.
Beside I'm still not sure if this just gives mit a 24bit grayscale image instead of 8bit..?!
Thanks for any help in advance! :)
use CV_BGR2GRAY instead of "CV_BGR2GRAY".
the former is an integral constant, the latter a char*
and, no fear, that will be 8bit grayscale.
I'm trying to run the mean shift segmentation using pyramids as explained in the Learning OpenCV book on some images. Both source and destination images are 8-bit, three-channel color images of the same width and height as mentioned.
However correct output is obtained only on a 1600x1200 or 1024x768 images. Other images of sizes 625x391 and 644x438 are causing a runtime error
"Sizes of input arguments do not match in function cvPyrUp()"
My code is this:
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvPyrMeanShiftFiltering( img, filtered, 20, 40, 1);
The program uses the parameters as given in the sample. I've tried decreasing values thinking it to be an image dimensions problem, but no luck.
By resizing image dimensions to 644x392 and 640x320 the mean-shift is running properly. I've read that "pyramid segmentation requires images that are N-times divisible by 2, where N is the number of pyramid layers to be computed" but how is that applicable here?
Any suggestions please.
Well you have anything wring except that when you apply cvPyrMeanShiftFiltering
you should do it like this:
//A suggestion to avoid the runtime error
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvCopy(img,filtered,NULL);
//Values only you should know
int level = kLevel;
int spatial_radius = kSpatial_Radius;
int color_radius = = kColor_Radius;
//Here comes the thing
filtered->width &= -(1<<level);
filtered->height &= -(1<<level);
//Now you are free to do your thing
cvPyrMeanSihftFiltering(filtered, filtered,spatial_radius,color_radius,level);
The thing is that this kind of pyramidal filter modifies som things acording the level you use. Try this and tell me later if worked.
Hope i can help.