Dear Tim, Hahaha, Sorry i didnt specify earlier. I use the bio formats <http://www.openmicroscopy.org/site/support/bio-formats5/about/index.html> based bfopen() <http://www.openmicroscopy.org/site/support/bio-formats5/users/matlab/> and i ran graythresh on the whole stack.
I got the same error with imread, its cause the stack is cut out (using fiji) from a larger stack of 33 images (3 channels, with 11 z-slices). I'm guessing imread() looks for more images as per the description but doesn't find them. Yes, Images does read it okay but only if i cut out the substack. If i don't, then it interprets the three channels as a time dimension, which isnt a pain at the moment but will be if i start using it for work. I realized that both the convert and the g[:] would slow me down but the hist function just wouldn't work without that kind of dance. Also, graythresh (http://www.mathworks.com/help/images/ref/graythresh.html) uses reshape to make it all one image which might also add to speed. The pull request is well and good but personally i would rather have a dedicated image histogram function like imhist: http://www.mathworks.com/help/images/ref/imhist.html which would give histograms based on input images. To me that's the only way to make life easier. ....maybe i'll write one :) Something about Images: do you think it possible to use the bio formats' .jar file to import images from a microscope format to Images? Opening a microscope format image file in the relevant software and then exporting it as tiff takes too long and i'd rather be able to access the images directly. I am considering writing my own method to get that done. But i know neither julia nor java so it will be a while before i can manage that. -Aneesh On Sunday, November 9, 2014 10:15:17 PM UTC+8, Tim Holy wrote: > > Dear Aneesh, > > How are you even opening that image file on Matlab? I get this error: > >> img = imread('control.mvd2 - XY point 3-1.tif', 1); > Error using rtifc > TIFF library error: 'TIFFReadDirectory: Incorrect count for > "ColorMap"; tag ignored.'. > > Error in readtif (line 49) > [X, map, details] = rtifc(args); > > Error in imread (line 434) > [X, map] = feval(fmt_s.read, filename, extraArgs{:}); > > > In contrast, julia's Images opens it without trouble :-). But one > important > thing to note: your file is a multitiff (there are 11 images in it), and > in > Julia the image is of size 512x512x11. If in Matlab you're just processing > one > 512x512 image, that fact alone will explain an 11-fold speed difference. > > That said, there was a problem with Julia's `hist` function; an attempt at > making it better is found here: > https://github.com/JuliaLang/julia/pull/8952. > With that pull request, running hist as > e, counts = hist(in_img, 65536) > is rather faster than what you're citing. (You also don't need all those > `convert` and `g[:]` calls, and in fact they slow you down.) > > --Tim > > On Saturday, November 08, 2014 07:34:24 AM Aneesh Sathe wrote: > > Hello! > > > > I use matlab for image processing and was thinking of moving some of my > > code to julia. But i found that the matlab function graythresh() was > > missing. So, i wrote my own version. > > > > Since I've been using julia for less than a week i doubt my code and/or > > algorithm is the best. So any input is much appreciated > > > > I've used the Images package to read my tif file. and then passed it to > the > > graythresh() function pasted below > > > > Comparisons for a test image: > > Matlab: Elapsed time is 0.013389 seconds. thresh value: 0.1294 > > Julia: elapsed time: 1.035032847 seconds thresh value: > 0.13013116644890854 > > > > Clearly, the julia code is slower but seems to give the right answer. > > > > where i think it might be slowing down: > > 1) the function is not a .jl file > > 2) the conversion to Array from the image format is inefficient > > 3) i'm doing loops wrong > > 4) the float values are slowing things down > > > > i tried using the profiler but couldn't quite get it to work for either > > just @profile graythresh() or @profile graythresh(img) > > > > Cheers! > > -Aneesh > > > > reference link for Otsu's thresholding: > > http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html > > > > > > Attached files: > > 1) the test code for Otsu's method with the graythresh function(remember > to > > run that cell before the rest) > > 2) the tif image i used for testing > > > > The relevant part of code from the ijulia notebook > > > > function graythresh(in_img) > > > > g=convert(Array,in_img); > > step=65536; > > > > #get histogram values > > e,counts=hist(g[:],linrange(minfinite(g[:]),maxfinite(g[:]),step)) > > > > im_len=length(in_img); > > > > tot_sum=0; > > for t=1:step-1 > > tot_sum=tot_sum+t*counts[t]; > > end > > > > sumB = 0; > > wB = 0; > > wF = 0; > > varMax = 0; > > threshold = 0; > > for t = 1:step-1 > > > > wB=wB + counts[t]; #weight background > > > > wF=im_len - wB; #weight foreground > > > > sumB=sumB+t*counts[t]; > > > > mB = sumB / wB; #Mean Background > > mF = (tot_sum - sumB) / wF; # Mean Foreground > > > > varBetween = wB * wF * (mB - mF)^2; > > # Check if new maximum found > > if (varBetween > varMax) > > varMax = varBetween; > > threshold = t; > > end > > end > > return e[threshold] > > end > >
