I have an image of 2061x2533 which represent an area of 429x349mm. When I open this saved image in Adobe Illustrator I would like the size to be exactly 429x349mm.
So I have a dpi value associated to my opencv image, but when I use cv.imwrite I did not find a way to set the dpi parameter to be considered by Photoshop or Illustrator.
Any idea?
As Micka said in his comment, opencv is for computer vision not for image editing. So you need another library to handle this.
You could for instance use pillow:
from PIL import Image
dpi = 150
cim = cv.imread(str(filename))
...
im = Image.fromarray(cim)
im.save('foobar.jpg', dpi=(dpi, dpi))
Related
I am trying to read a medical imaging data which is in .tif format using Octave . It so happens that only software from https://fiji.sc/ has the ability to read the medical images I have. A sample of the image that I am referring is this one. This image is readable in.tif format only in fiji. The image can also be converted to jpg image. Only after data points is visible to other image editing software. Now the issue is , I want to load it into octave and read it - at the moment it is not possible. The imshow() function in octave is not allowing me to visualize the given .tif file.
So, if anybody has experience in reading such file formats please let me know. Thanks.
Your linked image is a 16bit grayscale image, see $ gm identify -verbose hello.tif. So lets load it into GNU Octave:
img = imread ("hello.tif");
hist (img(:), 200); # show histogram
Ah!, the main information of your image is in the range 0-600 (probably the image aquisition system used had 11 or 12bit resolution), so lets scale and print this part as color encoded (viridis) image:
imagesc (img, [0 600])
colorbar
Is this what you want? Of course we can also use a gray colormap, try: colormap gray
If this still doesn't fit your need you should really explain what you expect to see....
imread() relies on image magic to do the conversion, some versions of which can only read TIFF in 8-bit mode (giving a warning message), but when and how this happens I do not know.
It works for me using a .raw ṕicture converted to .tif in Fiji. I am specifically interested in several spectral analysis from my pictures which are taken illuminating with 660 and 850nm.
I'm trying to use a two step process of employing Gimp to delete sections of images and then using Inkscape for the remainder of the image work.
Unfortunately, I'm seeing a resolution change when doing the export to PNG from Gimp.
The exported image is around 50% larger than the original, which impacts the quality.
Is there a way to keep the resolution constant when exporting the file?
Hopefully I'm just forgetting something, since I've spent some time away from image work.
Please let me know if any additional info is required.
In the interim, I'll try another tool to do the Gimp step.
THANKS!
Edit: Updated size to resolution.
For a bitmap/raster image, resolution (for Gimp: "Image print resolution", see Image>Print size) is indicative. The only thing that counts is the size in pixels.
If you have image window set to "Dot for Dot" (Edit>Preferences>Image Windows->General>"Use dot for dot" or View>Dot for dot) the image is displayed with the definition of your screen (around 100PPI fore regular screens, 20OPPI for high def ones (Retina, etc...).
When you create the image (File>New...), you can specify a print definition and a print size, and Gimp will compute the required size in pixels.
I used imagemaker tool to select targets for positive library, and generated a description file, i want to know how i can get the images cropped with the file?
Thanks.
Do you possibly mean the ImageClipper tool? If so, there is no implemented solution to save your cropped positives.
I have a series of images that I would look to loop through using iOS's [UIView startAnimating]. My trouble is that, when I exported the images, they all came standard in a 240x160 size, although only 50x50 contains the actual image, the rest being transparent parts that are just taking up space.
When I set the frame of the image automatically using image.size.width and image.size.height, iOS takes into images' original size of 240x160, so I am unable to get a frame that conforms to the actual parts of the image. I was wondering if there is a way using Illustrator or Photoshop, or any other graphics editing software for me to export the images based on their natural dimensions, and not a fixed dimension. Thanks!
I am a fan of vector graphics and thinks everything in the world should be vector ;-) so here is what you do in illustrator: file - document setup - edit artboards. Then click on the image, and the artboard should adjust to the exact size. You can of course have multiple artboards, or simply operate with one artboard and however-many images.
I would like to add a smaller image on top of a larger image (eventually for PiP on a video feed). I can do it by iterating through the relevant data property in the large image and add the pixels from the small image. But is there a simpler and neater way? I'm using EMGU.
My idea was to define an ROI in the large image of the same size as the small image. Set the Large image equal to the small image and then simply remove the ROI. Ie in pseudo code:
Large.ROI = rectangle defined by small image;
Large = Small;
Large.ROI = Rectangle.Empty;
However this doesn't work and the large image doesn't change. Any suggestions would be much appreciated.
Large image:
Small image:
Desired result:
If you using C++ API then the following code snippet should work:
cv::Mat big;
cv::Mat small;
// Define roi area (it has small image dimensions).
cv::Rect roi = cv::Rect(50,50, small.cols, small.rows);
// Take a sub-view of the large image
cv::Mat subView = big(roi);
// Copy contents of the small image to large
small.copyTo(subView);
Take care to not go out of dimensions of big image.
I don't know if this will help, i haven't used emgu. However this was how i was able to do image in image with opencv.
drawIntoArea(Mat &src, Mat &dst, int x, int y, int width, int height)
{
Mat scaledSrc;
// Destination image for the converted src image.
Mat convertedSrc(src.rows,src.cols,CV_8UC3, Scalar(0,0,255));
// Convert the src image into the correct destination image type
// Could also use MixChannels here.
// Expand to support range of image source types.
if (src.type() != dst.type())
{
cvtColor(src, convertedSrc, CV_GRAY2RGB);
}else{
src.copyTo(convertedSrc);
}
// Resize the converted source image to the desired target width.
resize(convertedSrc, scaledSrc,Size(width,height),1,1,INTER_AREA);
// create a region of interest in the destination image to copy the newly sized and converted source image into.
Mat ROI = dst(Rect(x, y, scaledSrc.cols, scaledSrc.rows));
scaledSrc.copyTo(ROI);
}
I have a lot of experience with EMGU. As far as I am aware the method your employing is the only direct way of display the sub-image data within your large image. You would likely have to refresh your larger image which would have the inherent effect of wiping your transferred data and copy the smaller image back over.
While a solution is possible I think the method is flawed. The required processing time will effect the display rate of any image in the larger viewing frame.
An improved method would be to add another control. Effectively you have your video feed window showing your larger image in the background and a smaller control on-top of this displaying your smaller image. Effectively you could have as many of these smaller controls as you like. You will in effect be displaying two images or video feeds in two different controls (e.g. image boxes). As you have the code to do so all you will have to do is ensure the order of which your controls are displayed.
I have assumed you are not programming the output to a Console Window. If you need any more help please feel free to ask.
As for the comments EMGU is written in C# and while appreciate your view on not calling EMGU OpenCV why should it not be tagged as an OpenCV orientated question. After all EMGU is simply OpenCV library with a c# wrapper. I have found many resources on OpenCV useful for EMGU and vice versa.
Cheers
Chris
Based on #BloodAxe's answer, using EMGU 3.4 the following works:
// Define roi area (it has small image dimensions).
var ROI = new System.Drawing.Rectangle(100, 500, 200, 200)
// Take a sub-view of the large image
Mat subView = new Mat(bigImage, ROI);
// Copy contents of the small image to large
small.CopyTo(subView);