4

We have an image in hdf5 file, which we want to extract and drop it into the BookDown pdf

here is the code which is doing that

insertImage <- function(hdfFilepath, datasetPath) {
  library(rhdf5)
  library(magick)
  hdfimagedata <- h5read(hdfFilepath, datasetPath)
  image <- image_read(hdfimagedata)
  image <- image_scale(image,"300%")
  plot(image)
}

what every I give the scale the image size does no increase and sticks to the size shown below The image is a very HQ image

We have also tried with option of image_scale(image,"2000x2000!") and we also tried fig.height and fig.width options, but did not yield the expected result. The image size remains the same irrespective of any number assigned to height and width

How to enlarge the image i.e. zoom to fit to page

PN: we don not have any problem with render quaility

sample pdf with image

Hi, I got it to maxime but now the image overlaps the text

  image_resize(image,geometry_size_pixels(width = 300, height = 300))

Image overlapping text

And the Image rendered is Inverted too.

here is the header defined in index.rmd

--- 
title: "Document"
author: ""
site: bookdown::bookdown_site
output: bookdown::pdf_book
documentclass: book
classoption: openany,oneside
link-citations: NO
geometry: margin=2cm
description: "This is a minimal example of using the bookdown package to write a book."
language:
  ui:
    chapter_name: 'Chapter'
---

please help

SID
  • 99
  • 9
  • Can you find a way to isolate the problem to either `magick` or `bookdown`? – AkselA Oct 20 '20 at 08:06
  • Hi. There seems to be no problem with the magick library as we have rendered a file from the hdf5 and saved it to a location. and the size and the quality remains same. I think its the bookdown – SID Oct 20 '20 at 09:49
  • I've just tested your function for inserting an image from an hdf5 file in a `bookdown` project and it works like a charm. If you think that `bookdown` is the issue, please provide some details (for starters, the YAML header). Providing the hdf5 file could also help. – Martin C. Arnold Oct 20 '20 at 22:48
  • Was the inserted image had the same dimensions for height and width? Please make sure to use an image with more height than width..... For me the square image insert perfectly – SID Oct 21 '20 at 00:11
  • It was a 24bit 227x149 image of a rose from [here](https://support.hdfgroup.org/HDF5/Tutor/h5image.html). Again, I encourage you to provide some details about your bookdown project. – Martin C. Arnold Oct 21 '20 at 07:59
  • @M.A. have added the code. please do let me know if we need more code to debug this – SID Oct 21 '20 at 13:36
  • Looks fine too me. Could you provide the hdf5 file? – Martin C. Arnold Oct 22 '20 at 14:14

1 Answers1

2

The Solution to the above problem is

insertImage <- function(hdfFilepath, datasetPath) {
  library(rhdf5)
  library(magick)
  hdfimagedata <- h5read(hdfFilepath, datasetPath)
  image <- image_read(hdfimagedata)
  image <- image_scale(image,"300%")
  par(mar=c(0,0,0,0))
  plot(image)
}

This helped

par(mar=c(0,0,0,0))
SID
  • 99
  • 9