Parsing for RGB regions over thousands of high resolution image files - scala

I have lots of high resolution image files that have regions of colors, basically blobs with different rgb values. I need to go through the images and for every image make a text file that contains the coordinates to one pixel in every blob. Because I have so many files the script needs to be fast. I already wrote some scala code to do the task except it only saves locations for one blob per specific RGB value, meaning if I have two blobs of the same color that are not connected it will only save one the location for the first one found. The solution to this is for each images copy the location and colors to a map and when I find a blob flood delete (flood fill except delete instead of fill) and then keep parsing on the new map. However, I think this will make run time horribly slow because I will have to go through the entire image to add it to a map before even starting the parse. Thoughts? Am I going about this all wrong?
Thanks.

Related

How can I convert large number of EPS files to PNG with a desired sizing?

I have bulk images in EPS having varied dimensions, all stored in a one folder.
How can I convert them all to PNG having a fixed dimension of 4500x5400 and make them store in another folder?
Can this process be done in one go, instead of manually doing it for each image?

Segmenting individual blobs connected by boundaries

Let's say I have the following image.
I want to consider these two blobs as two separate blobs; however, finding connected components labels them as a single component because they are touching.
I tried img = bwmorph(img, 'branchpoints'); and that does segment and erode these two blobs but that also erases blobs other blobs. For instance, in the following image, the upper left structure has been erased, but that structure should not be erased and moreover, I would like to segment that structure as two blobs that can be evidently seen.
The unfilled blob on the left has disappeared. How to get around this problem?
here's an idea, use imfill to fill holes in your blobs:
bw=imfill(im,'holes');
then do bw-im and get this:
you can take it from there...

How to overwrite part of a png?

Given a png image and a set of data to write to it, is it possible to overwrite pixels in the existing png in a particular area of interest? For example, If I have a block of data in a rectangle between pixels (0,0) (5,10) would it be possible to write this data as a block into a 10X10 png without any concern for the area not being overwritten? My use case is that I have map tiles where half the data will be in one tile and half in the other, with the blank pixels being white squares. I would like to combine them by simply writing the non-white pixels directly to the existing png in a block without having to open, combine, then re-write the entire png. Does the structure of a png allow this?
I'm loath to claim that this is impossible, but it is certainly complicated.
First of all, pixels of a PNG are (sometimes) interlaced, so you'd have to calculate the locations of your target pixels based on the Adam7 scheme.
Furthermore each row is independently filtered, so you'd have to transform each row of your source using the filter of the target row. Depending on the filter you'd also have to adjust additional bytes on the border of the updated target bytes. Straight from the horse's mouth:
Though the concept is simple, there are quite a few subtleties in the actual mechanics of filtering.
Finally, all the filtered bytes are compressed using a generic compression algorithm called "deflate." Unless you want to decompress the whole thing beforehand, you need to make sure both that (1) your source data can be properly decoded and (2) the bytes near the border of the target bytes are properly compressed in the context of their new neighbors.
I'm not a compression expert, so I won't argue in more detail. One piece of good news is that the algorithm seems to preserve independence between distant regions due to its sliding window scheme: data are only compressed based on data in some preceding range, say 13,000 bytes.
If this seems at all easy to you, give it a try. If you're like me, though, you'll just decode the whole thing, overwrite the pixels as bitmap data, and encode the result.
This is practically impossible because the pixels data (after a row-by-row "filtering") is compressed with ZLIB. And it's practically impossible to change part of a compressed stream.

How does one embed a file inside of an image? iOS iPhone

There is an app on the app store called active photo (http://itunes.apple.com/us/app/active-photo/id366798464?mt=8) that allows you to embed a hidden image or .exe file inside of an image. I would like to know how to do this regrading adding images to images, kinda like sub images in the original image.
I've been looking into metadata but no tag seems to be big enough to hold an NSData representation of the second picture.
How would one go about adding any type of file to an image, either through embedding or metadata, that would allow the image to be sent though email and or text message and still retain the data?
Thank you.
This is known as steganography.
I would imagine the simplest way of hiding a file inside a JPEG image is just to alter its pixel data in such a way that the compression doesn't damage it but is subtle enough that an interceptor can't detect the hidden data.
I don't think it is possible with JPEG because it's a lossy compression so you would end up corrupting the embedded file. But PNG uses a compression method similar to Deflate, which is loseless.
I have started writing a program like this. The idea was to hide bytes of data by splitting them into the least significant bits of pixels' color channels. Let me do some examples.
An RGB-8 image represents a pixel with 3 bytes, one for red, one for green and one for blue. I store 3 bits into red channel, two into green (human eye is more sensitive to green color) and 3 into blue. So I embed one byte per pixel. Similarly with RGBA-8 image I do 2-2-2-2. This of course involves some bitwise operations.
Things become more interesting with RGB(A)-16 images, where there are two bytes per channel. I use the entire least significant byte of every channel with minimal distortion (worst case 255 / 65535 = ~3.9%) and store up to 3 or 4 bytes of data per pixel. Not bad!!
Moreover there are no complex bitwise operations in this case, a single assignement does the job.
There are lot of improvement to it. I thought to ask the user a password, hash it and seed a secure pseudo random number generator, then no longer move pixel by pixel but instead asking the generator for a new random index.
The drawback of this solution is that the more data has already been embedded, the slower it becomes, because the generator will give more and more occupied indices. But it is much more secure in this way. To make it even more safer I thought to introduce noise data in the untouched pixels, in order to hide the positions of the true data.
As you can see you can do a lot with PNG images! If you are interested I can give the code I wrote so far.

Perl+Image::Magick usage: how to assemble several areas in one image into a new image?

I'm new to ImageMagick and haven't figured out how to assemble several areas into a new image.
E.g., I know the "geometry" of words "hello" and "world" respectively in an image, what I need to do
is to retrieve the word images and put then into one line image while keep their relative positions.
Question1: Suppose I use the perl API, how should I use Composite() or other correct methods to do this?
my $geom = sprintf('%dx%x+%d+%d', $word->{width}, $word->{height}, $offsetx, $offsety);
$x = $lineimg->Composite($wordimg, $geom);
warn "$x" if "$x";
Suppose $lineimg's size is big enough to hold all word images and the geometry has been computed.
This code gives out a complain by ImageMagick:
Exception 410: composite image required `Image::Magick' # Magick.xs/XS_Image__Magick_Mogrify/7790 ...
Question2: currently I only know how to crop a word image out of the original one and then Clone() method
to restore the original image. Is there a way to copy instead of crop a specific area from a image? This way
can save the time to copy back and forth the whole image several times.
Does anybody know how to write this kind of processing? I appreciate all your help and suggestions!
-Jin
From the sounds of things Image::Magick is not the right tool for your task. Image::Magick is generally for manipulating entire image - filtering, scaling, converting between formats etc.
Consider the GD module, which can do just about any of the drawing operations you will need.