Skip to main content

Posts

front end - UI performance with large image data

Some days ago, I built a small program for some of my colleagues to analyse cell images. One minor part of the user interface was the selection of the region of interest. The images are large and need to be analysed in full-size but for the selection, you don't need to see them in full-size. The most direct way to implement this is to use the original image and only show it in a smaller size. With this the original image dimensions are preserved and I can use the original coordinates for the selection of the region. Let me give a small function that does nothing more than showing an image and a rectangular region that can be moved: roiSelector[img_] := DynamicModule[{ pt = Round[ImageDimensions[img]/2], dim = Round[ImageDimensions[img]/6] }, LocatorPane[Dynamic[pt], Show[ HighlightImage[ img, Dynamic@{Rectangle[pt - dim, pt + dim]} ], ImageSize -> 512] ] ] img = Import["http://biology.usf.edu/cmmb/images/cells2.jpg"]; roiSelector[img] ...

Apply a Function Pairwise

I'm new to Mathematica I'd like to apply Mean pairwise to a list to achieve the following. badSource = {{0, 0}, {1, 1}, {2, 0}, {3, 1}, {4, 0}}; badInterpolation = {{.5, .5}, {1.5, .5}, {2.5, .5}, {3.5, .5}}; ListLinePlot[{badSource, badInterpolation}, Mesh -> All] How can this be done in general? Do I need pure functions? Answer You need partitioning, Partition and parameters: 2 for pairs, 1 for unit overhang/offset, and then averaging each pair, using Map , short-notated /@ . Partition[{a, b, c, d}, 2, 1] {{a, b}, {b, c}, {c, d}} These will all make the averages: Mean /@ Partition[N@badSource, 2, 1] MovingAverage[N@badSource, 2] ListConvolve[{{.5}, {.5}}, badSource] ListCorrelate[{{.5}, {.5}}, badSource] Last two suggested by J. M.

Manipulate with a variable number of sliders

I have a function that operates on a list of parameters of variable-length $n$. I would like to create a Manipulate[] that has $n$ sliders, one for each list element, each considered a separate parameter. The syntax Manipulate[expr,{u,...},{v,...},...]] does not lend itself to this, as it is geared toward a fixed number of parameters known in advance, and referenced by separate variable names. I have started exploring preparing a list of arguments to Manipulate[] and then using Apply[] , but this seems tricky and complicated. Anyone come upon this conundrum before? Answer The Advanced Dynamic Functionality in Mathematica documentation has the following example that looks like what you need. DynamicModule[{n = 5, data = Table[RandomReal[], {20}]}, Column[{ Slider[Dynamic[n], {1, 20, 1}], Dynamic[Grid[Table[With[{i = i}, {Slider[Dynamic[data[[i]]]], Dynamic[data[[i]]]}], {i, n}] ]]}]] It builds a list of controllers ( Slider -s in this particular case) by using the fact that...

Is it possible to add some pattern to $Assumptions

I apologize if it is a too elementary question but I could not find the appropriate documentation so far. My goal is simple. I would like to add some assumptions that are defined in terms of patterns rather than symbols. For example, I would like to something like this $Assumptions = { a[ ___ ] > 0 }; In my ideal world, this should set every expression with the Head a should be considered positive. Is it possible in Mathematica? EDIT: Thanks. Following the first comment and the first answer, I did the following experiment. I still got puzzled about the result. Maybe it is just because of the intricate interaction between Integrate and $Assumptions . $Assumptions = {A[___] > 0, B > 0}; Integrate[ Exp[ - A[x] t] , {t, 0, \[Infinity]}] Integrate[ Exp[ - B t] , {t, 0, \[Infinity]}] (* output *) ConditionalExpression[1/A[x], Re[A[x]] > 0] 1/B In this example, Integrate does not make use of the fact A[___]>0 . Answer This is correct; you can also use the following forms...

list manipulation - Find longest monotonically increasing subsequence containing final two elements

I'm interested in finding the longest monotonically increasing subsequence of a sequence containing the final two elements . This question addresses my question without the italicized requirement. For example, given {3,4,6,7,5,8} , the function should return {3,4,5,8} , not {3,4,6,7,8} . (In fact, I only need the length of that longest subsequence, but a function returning the subsequence is fine too.) We may assume that lst[[Length@lst-1]] and that the elements of lst are distinct. EDIT: Note that this is the same problem as determining the longest increasing subsequence including the final element - given such an algorithm, apply it to Rest@lst to get the longest increasing subsequence containing the last two elements. Answer Using Leonid Shifrin's solution from the Q&A you mentioned: longestSequence[{seq___, a_, b_}] := With[{list = Select[{seq}, # Join[LongestCommonSequence[list, Sort@list], {a, b}] ]

parallelization - SSH known hosts in Windows (Error code = 124)

I had to re-install Raspbian OS and now it has new SSH key. SSH clients usually let ignore this fact and save the new key, but not now. Mathematica gives no way to go if the Host Key was changed. I get an error SSH received a different Host Key while launching kernel 'Raspberry Pi'. Error code = 124. when trying to start remote kernel and I have found no any information about where is the Mathematica's SSH client on Windows... I just need to clear known hosts... The easy way is to change Raspberry's IP, but it's far less interesting, moreover not always possible

list manipulation - How to rearrange the matrix elements in a special way?

This is a follow up on this question . Consider a matrix m1 as m1 = {{1, 2, 3}, {4, 9, 5}, {6, 7, 8}}; In MatrixForm it looks like I want to rearrange the elements in a way such that it looks like Consider another example. m2 = {{1, 2, 3, 4, 5}, {6, 17, 18, 19, 7}, {8, 20, 25, 21, 9}, {10, 22, 23, 24, 11}, {12, 13, 14, 15, 16}}; In MatrixForm , And I want to transform this into Basically, I want the boundary elements to be sorted in a counter clock-wise with the smallest element at the center-right. How can I do this?