Save image that has been segmented in matlab - image-processing

I would like to know how can we save an image that has been segmented (using fuzzy c-means method) in MATLAB where the end product are images of each cluster group. I would like to save the images to use later.

I assume you just want to save an image, this should be independent on how you produces that.
If I understood correctly you just have to use the function
imwrite(M, filename)
Where M is the matrix containing your image data. You just need to do this for each matrix/image you have.
Then you can reload the image from filename using imread.
imread(filename)
Note that if you want to specify the format for imwrite and not obtain it via the filename extension, you just to add an additional parameter as follow:
imwrite(M, filename, format)

Related

Extract image thumbnail from data

I'm using CGImageSource to read Exif (and other) data of image file. Some image files are embedded with their own thumbnail image (used for file icon).
I know I can extract a file icon using NSWorkspace.shared.icon(forFile:), but I'm already holding a CGImageSource ref, (and not sure of the cost of icon(forFile:) in performance).
Sure I can use the CGImageSourceCreateThumbnailAtIndex(.. to generate a thumbnail, but it would be more efficient to just fetch it (if it exists).
A 'you cannot do that' answer is also a good answer, (then I can go with plan B).

Python-fu/gimpfu parameters - What does "image" mean?

I've been trying to switch from script-fu to python-fu, and I can't figure out what I'm supposed to pass for the "image" parameter. In script-fu it was just an integer, but when I put the same integer into python-fu, it just says it's the wrong type. Same with strings and floats... what am I supposed to put in here? The documentation just says the parameter it takes is "IMAGE" but what does that mean? Where do I find it? How do I get it?
pdb.gimp_image_get_layers(image)
Here's a picture of the interpreter.
You pass an Image object -
Most of the parameters that are only integers in script-fu are not to be used - in their place, you have to pass an actual object reference. ANd how do you get those?
Simply all PDB functions and methods return these objects already - not their numeric IDs, like it happens in script-fu.
So, for Image, you either get the Image as parameter for your python-fu function, or on a call to pdb.gimp_image_new.
If, as it is often the case, you are making tests on the interactive console, you have to get references to the active images. In that case, call
gimp.image_list() to get a Python list with the currently open images - the image at index 0 on this list is the rightmost (newest) open image on the screen -so just do image = gimp.image_list()[0] to get a reference to it.
While you are at it, explore the image object with dir(image) you willfind it is populated with attributes and methods that are handy shortcuts to otherwise hard-to-type pdb calls. For example, image.layers gives you a Python list with reference to all layers on the image (as actual Layer objects, not their IDs), image.width gives you the width, and calling img.new_layer() creates a new layer and adds it to the image - this call has optional parameters to specify its name, width, height and so on.
As a last resort, there are reserved methods on the gimp module that can convert a numeric ID to the actual objects: '_id2display', '_id2drawable', '_id2image', '_id2vectors' - you should not need to use those. If you ever find your self needing to use those in the body of a script, due to some pdb function returning IDs instead of objects, please fill a bug report on GIMP's bugzilla.

How to realize ROI (region of interest ) in EDSDK?

I need to take picture with EDSDK and save to host only ROI of Image. Do I need to use EdsGetImage? How can I realize this? I don't understand how to use EdsGetImage.
EDSDK only provides complete, uncropped image download to Host in either JPG or CR2. You may crop once the original is downloaded and decoded. You might want to use EDSDKs internal EdsGetImage, with EdsRect and EdsSize parameters to do "cropped" retrieval from the image source.

Rails: randomly pick a image as background image

I'm making a page with a background image, and I want to make the background image changes automatically.
The images have been saved in directory already.
One possible solution would be set up a BackgroundImage class, and make those images record in the database, so #backgroundimage = BackgroundImage.all.shuffle.first, and then use it in view page like img_tag #backgroundimage
Another approach would be something like <img src='backgroundimages/image#{#random-number}>? I think this is possible if I name those images like image1,image2,and get a random number each time in the controller. But it requires renaming images by hand.
You could put the images in one Folder then read all filenames and return a random image name so you whouldnt need a naming schema or a database backed model. Like this:
def random_image
blacklist = [".", ".."]
file_names = Dir.glob("/path/to/images/*")
blacklist.each do |blacklsited|
file_names.delete(blacklisted)
end
"/webserver/path/to/images/{files.shuffle.first}"
end
So in the view you could call the helper method random_image.
try this out
BackgroundImage.order("RAND()").limit(1)
depending on your database it could be ‘RANDOM()’ or something similar
it generates sql query like this
SELECT "background_images".* FROM "background_images" ORDER BY RAND() LIMIT 1

How to update model in a paperclip processor?

I've build a processor that determine which image format is best to compress my model attached thumbnail. The processor simply build images in png and jpg and check which one is the smallest.
Since Paperclip use the original thumbnail format to build it's thumbnail style URL I had to create a field in my model to store the format of each of the styled thumbnail.
ex: thumbnail_small_content_type, would be "image/png"
In my processor I tried to save the format by using the Paperclip:attachment method : instance_write.
#attachment.instance_write "#{#style_name}_content_type", "image/#{optimised_format}"
Strangely it work perfectly when a create a new model, but failed to work when I use the paperclip method reprocess! to crop my image. Any idea how I could workaround that limitation?

Resources