Using Jupyter notebook with LaTex. Images not exported to pdf via LaTex - latex

New to Juypter, trying to use it with Latex. Everything works fine except for the images. I used this tutorial: https://www.youtube.com/watch?v=m3o1KXA1Rjk&t=149s
Png Images are fine in markdown, i.e
But LaTex cannot determine size of png images. If I save the image as pdf I get the same issue. If I save the image as eps then LaTex complains that it cannot convert eps to pdf.
Has anyone had this issue? Anyone know how to solve it?

PNG images always contain the size in pixels.
Optionally, they can include a chunk of data named pHYs. This contains the resolution of the image. If this chuck is present, you should be able to find the actual text pHYs in the file.
If this chunk is missing from the PNG file, the scale of the image can not be found.
If you are on a UNIX-like operating system you could use grep or hexdump to check for the text pHYs in the PNG file. The identify program from the ImageMagick suite also can display the resolution of PNG images.
Note that there is an error in the video. The author first uses latex and then pdflatex three times. That is not a good idea, since they have different capabilities w.r.t. graphics. Stick with pdflatex.

Related

Issues with reading tif file in Octave

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.

ghostscript compression distorts graphics

I am writing a large document in LaTeX and generate most of my schematics using Inkscape. I store all Inkscape schematics as PDF and include them using the default latex figure environment.
Because the final result is quite large I then compress the document using ghostscript, using the following bash command:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/printer -sOutputFile=${FNAME}_compressed.pdf $FNAME.pdf
$FNAME is the PDF file name. I noticed that the compressed PDF distorts some of the PDF graphics generated by Inkscape, mostly replacing solid black lines for dashed ones.
I uploaded a distortion example. The uncompressed original is on the right. Ghostscript distorted version on the left.
The distortion happens regardless of the dPDFSETTINGS flag. As far as I understand Ghostscript compression works by regenerating the PDF code so that it looks the same, but obviously this is not working correctly. However, the only images affected appear to be the Inkscape generated PDFs. Matplotlib generated ones appear to be fine.
Could you help me figure out, what is wrong here?
Thanks in advance

Imagemagick: Identifying when to use sampling-factor for jpeg compression

I am automating conversion of source PNG images to JPEGs of a predefined dimension. For most the images, I don't need to provide the sampling-factor and happy with the output quality and file size. However, a few of the files get heavily distorted with artifacts. For such files, I currently manually provide the option '-sampling-factor 1x1' to get the desired output jpeg, though bigger file size.
Is there an way to identify before hand which PNG src file needs the usage of sampling-factor for conversion? That will help to pull it in the script.

GeoTIFF files in ImageJ

I am trying to open GeoTIFF file in ImageJ. It is opened as blank black image. But I want the view as its JPEG converted image. Please If anyone can help me. I want to process that image for Oil Spill Detection.
I would recommend using the Fiji distribution of ImageJ. It includes the Bio-Formats importer which supports a huge number of image formats. It looks like it has support for GeoTIFF tags, as well.
Also, sometimes images "look" black but aren't truly. See this FAQ entry.

Inkscape + pdftex?

I have a small drawing in Inkscape and I want to embed it in a LaTeX document which I compile using pdftex. pdftex seem to have an oddity of not accepting .eps. infact if what I understood is correct the only vector graphics format it accepts is pdf. When I save my drawing in Inkscape as pdf then what I get is a pdf with a full page with my drawing in the upper corner.
Is there a way to import an Inkscape drawing to pdftex and ignoring this page size? Or do I need to start fiddling with the page settings to make the page size exactly fit the size of my drawing?
So it turns out that Inkscape has a button on the Document properties titled "Fit page to selection" which makes this easier. Oh well.
Yes, pdftex does not accept eps.
I have used inkscape to make figures that I incorporate into .tex documents that I then process with pdflatex. And yes, I set the page size in inkscape so that the figure fits.
You could also try to export to .eps from inkscape, then convert to pdf with the "epstopdf" tool.
Are you giving the optional scaling parameters to \includegraphics? PDF handles bounding boxes differently from encapsulated postscript, and auto-sizing does not seem to work as well.
As far as I know, you have to adjust the bounding box resp. paper size in your PDF. There are tools like eps2pdf to convert EPS to PDF with the same bounding box.
You can even fully automate the process of converting your svgs into pdfs, since inkscape can be called from command line. For instance, the following makefile code does the job (copping and converting) for me:
# svg -> pdf
$(GRAPHIC_DIR)/%.pdf: $(GRAPHIC_DIR)/%.svg
cp $(GRAPHIC_DIR)/$*.svg $(GRAPHIC_DIR)/$*-crop.svg
inkscape --verb=FitCanvasToSelectionOrDrawing --verb=FileSave --verb=FileClose $(GRAPHIC_DIR)/$*-crop.svg
inkscape -A $(GRAPHIC_DIR)/$*.pdf $(GRAPHIC_DIR)/$*-crop.svg
rm $(GRAPHIC_DIR)/$*-crop.svg
Moreover, cropping pdf files can be also done using pdfcrop.

Resources