0

I am writing a prototype of an image manipulation program in MATLAB and am hoping to port it to javascript once the prototyping phase is done.

I am not very familiar with javascript but there seem to be many image processing libraries available so my guess is most of the basic image manipulation functions I use in MATLAB are already implemented somewhere. However one of the more powerful functions I am using in MATLAB is called "regionprops", basically it figures out the strongly connected components of a binary image and outputs a bunch of stats pertaining to each "component", such as the area, the bounding box, the barycenter, etc.

What is the shortest way (i.e. with minimal implementation on my part) to having this available in js ? As a last resort I will convert the image to a graph in order to use a strongly-connected-component lib, if I can avoid this (and the subsequent image-related calculations) I would like to know.

Pointers to docs and libs are much appreciated ! Thanks, Tepp.

sg1234
  • 600
  • 4
  • 19
  • I hope you're not planning to actually run a web application that does this. Running CPU-bound code on a single-threaded application that's also simultaneously handling web requests is a really bad idea, because it'll block the whole thread until finished and your users will have to wait for everyone else's requests to finish first. – Akshat Mahajan Apr 14 '16 at 02:33
  • thanks for your comment, not sure i understand all the subtleties though: why single-threaded? my plan is to have the user upload a file that will be analyzed on the server. once the server is done it will respond. however, the request / response could be async (e.g. pushing the stats in a db). i am probably missing something? – sg1234 Apr 14 '16 at 02:48
  • Node.js is single-threaded by design. When you run a Node.js application as a server, it is a single thread handling everything. The problem with a single-threaded server application is that it should not be used for CPU-intensive computation because it will drop everything else it is doing, finish the CPU computation, and only then get back to handling everything else. – Akshat Mahajan Apr 14 '16 at 02:54
  • Imagine you have a hundred users all waiting for their individual files. They all submit massive files, each of which takes 5 seconds to complete. The first user waits 5 seconds, but the second user has to wait 10 seconds because he has to first wait for the first user's stuff to finish because Node.js is single-threaded. The hundredth user would have to wait for 500 seconds. See the problem? – Akshat Mahajan Apr 14 '16 at 02:56
  • Then again, I could well be mistaken in Node's abilities in this domain. Just pointing out that CPU-intensive tasks are not the server's job. If you have to run CPU-intensive tasks, I would recommend designing your architecture differently so that Node hands off files to another system process and then collects the process once its done. This will prevent needless wait times on the part of the user. – Akshat Mahajan Apr 14 '16 at 02:59
  • Thanks for the feedback, I will look into the correct architecture. But since I eventually want to port the calculations to the client side, I still think (hope) javascript makes sense ? – sg1234 Apr 14 '16 at 15:23
  • Node.js doesn't run on the client, though. If you're talking about browser-side Javascript, oh, then you can forget about everything I just mentioned. :) It's much easier to do this task on the browser than on the server - modern browsers provide a lot of meaningful features in this regard. – Akshat Mahajan Apr 14 '16 at 15:42
  • Thanks for this, I will edit my question to reflect the fact that I am interested in any javascript APIs to help with this image processing problem. – sg1234 Apr 15 '16 at 03:49

0 Answers0