Concatenated sequence automatic bounds update

18 views
Skip to first unread message

Masoud Ramuz

unread,
Jan 15, 2019, 10:40:12 AM1/15/19
to Icy imaging
Dear all,

I'm concatenating sequences on the Z axis through
            concS = SequenceUtil.concatZ(seqBundle, false, false, true);
The completed sequence shows the following:
Auto-bounds/Refresh on the histogram is not working despite looking ticked.
Unticking and reticking the box fixes it:

I'm wondering if there's a way to just have it start with the properly working auto bounds?
I've tried setting
            concS.setAutoUpdateChannelBounds(true);
but this does not solve the issue.

Stephane

unread,
Jan 15, 2019, 11:17:54 AM1/15/19
to Icy imaging
Dear Masoud,

That should fix your problem:
concS.updateChannelsBounds(true);


- Stephane

Masoud Ramuz

unread,
Mar 18, 2019, 12:38:47 PM3/18/19
to Icy imaging
Dear Stephane,

Sorry for getting back to this so late, I hadn't had much chance to properly test this solution before.
Sadly this doesn't work for me, no matter where in my code I try to implement your solution.

To clarify things further, please see the image below. I'm creating a concatenated sequence out of isolations of images created from specific locations of my acquisition. This is done by stacking the images from these 4 ROI (green) into one sequence's Z axis (Pos1), using
SequenceUtil.concatZ()
As you can see, the Pos1 sequence's histogram settings do not match auto-bounds for any of the images inside of it despite setting
concS.updateChannelsBounds(true);
I've tried to set this after concatenation of the sequence, as well as much later in my code.

Right now I'm forced to manually turn auto-bounds off and on again for each concS (we have about 5 to 8 of these during an experiment), so it would be nice if there was a way to solve this issue.


Cheers,

Masoud

Stephane

unread,
Mar 20, 2019, 5:21:05 AM3/20/19
to Icy imaging
Dear Masoud,

Sometime it's a bit tricky to understand why the bounds didn't got updated correctly, specially when you create the sequence or/and the viewer before setting the data into it.
What you can try is to use concs.beginUpdate() / concs.endUpdate()  before and after changing sequence data.
It would be nice to have, if possible, the piece of code generating concs (just that part) as i cannot reproduce the issue here.

- Stephane

Masoud Ramuz

unread,
Apr 2, 2019, 9:47:30 AM4/2/19
to Icy imaging
Dear Stephane, the begin/endUpdate doesn't help.
I'll post some code below:

Initial setup of the image splitter gets sequences with ROIs drawn on them and will crop to these ROIs and concatenate the resulting images into one sequence:


   
Splitter (ArrayList<Sequence> acquiredSeqs, File transfoFile) throws InterruptedException{
       
System.out.println("started S1");
        rois
= new ArrayList<ROI>();
        cropImages
= new ArrayList<IcyBufferedImage>();
        seqBundleList
= new ArrayList<>();
        concSeqList
= new ArrayList<Sequence>();
        fuck
= false;
        SU1
= null;
        doneSU
= false;
        init
= true;
       
ArrayList<Sequence>    seqBundle = null;

       
System.out.println("splitter checkpoint 1");
       
for (int r = 0; r < rois.size(); r++) {
            rois
.get(r).setName(rois.get(r).getName() + " Channel#" + Integer.toString(r));
            rois
.get(r).setShowName(true);
       
}
       
       
for (Sequence acquiredSeq : acquiredSeqs) {            
       
// get current position
       
String pos = ExtractPos(acquiredSeq);        
       
       
// get image type
        dataType
= acquiredSeq.getDataType_();
       
       
// get contours for splitting
        rois
= acquiredSeqs.get(0).getROIs();
        possibilities
= new String[rois.size()];
       
       
//Create image per ROI
        seqBundle
= new ArrayList<Sequence>();
           
for(int r = 0; r < rois.size(); r++)
           
{
                ROI roi
= rois.get(r);
               
Rectangle5D bnd = roi.getBounds5D();
               
IcyBufferedImage img = new IcyBufferedImage((int)Math.round(bnd.getSizeX()), (int) Math.round(bnd.getSizeY()), 1, dataType);
             
               
//TODO: Before each crop, apply transform. After each crop, reset base image
               
//change bnd to after-transform corners
               
IcyBufferedImage copyImg = acquiredSeq.getLastImage();
               
               
// store image
                cropImages
.add(r, img);
             
               
// create sequence
               
Sequence s = new Sequence(img);
               
               
// change sequence name
                s
.setName(roi.getName());
               
               
// show it
//                Icy.getMainInterface().addSequence(s);
               
               
// ready ROI options
                possibilities
[r] = s.getName();
               
               
// create bundle of split images from single sequence(position)
                seqBundle
.add(s);
           
}
           
// pair bundles with their pos name
            seqBundleList
.add(new BPpair(seqBundle, pos));

       
//Concatenate split images
       
if (!MultiFretIcy.PS.offlineBool) {
           
Sequence[] seqBundle2 = new Sequence[seqBundle.size()];
            seqBundle2
= seqBundle.toArray(seqBundle2);
           
           
// create sequence
           
Sequence concS = new Sequence();
            concS
.beginUpdate();
            concS
= SequenceUtil.concatZ(seqBundle2, false, false, true);
            concS
.endUpdate();
           
           
// set sequence name
            concS
.setName(pos);
           
           
// set channel names
           
for(int r = 0; r < rois.size(); r++)  {
                concS
.setChannelName(r, rois.get(r).getName());
           
}
           
           
// show it
            concS
.updateChannelsBounds(true);
           
Icy.getMainInterface().addSequence(concS);
           
           
// List
            concSeqList
.add(concS);

           
System.out.println("made thing");
           
System.out.println("Triggered split");    
           
           
// Initial split so SU has something to work with
           
Split(new AcquiredObject(acquiredSeq.getLastImage(),System.nanoTime(),pos),transfoFile,false);            

       
}
   
}

The following Split method is called every time a new acquisition is made, and will crop the acquisition in the same way as before and put the image data in the right concatenated sequence:

    public void Split(AcquiredObject acqObj, File transfoFile,boolean x) {
       
// Update images
       
IcyBufferedImage newImage = null;
       
try {
            newImage
= acqObj.acqImg;
       
} catch (Exception e) {
           
MessageDialog.showDialog("ERROR ACQUIRING IMAGE");
            e
.printStackTrace();
       
}
       
       
for(int q = 0; q < seqBundleList.size(); q++) {
           
if(seqBundleList.get(q).Pos.equals(acqObj.position)) {
               
ArrayList<Sequence> seqBundle = seqBundleList.get(q).Bundle;
               
for(int r = 0; r < rois.size(); r++)  {            
                    seqBundle
.get(r).beginUpdate();
                   
                    ROI roi
= rois.get(r);
                   
Rectangle bnd = roi.getBounds5D().toRectangle2D().getBounds();
                   
IcyBufferedImage img = cropImages.get(r);
                    img
.copyData(newImage, bnd, null);
                   
                    seqBundle
.get(r).removeAllImages();
                    seqBundle
.get(r).addImage(img);
                   
                   
Sequence concS = null;
                   
for (Sequence s : concSeqList) {
                       
if (s.getName().equals(acqObj.position)) {
                            concS
= s;
                       
}
                   
}
                   
                   
if (concS == null) {System.out.println("No Matching concS");}
                   
                    concS
.beginUpdate();                  
                    concS
.setImage(0, r, IcyBufferedImageUtil.scale(img, concS.getWidth(), concS.getHeight())); init = false;
                    concS
.endUpdate();
                    concS
.updateChannelsBounds(true);                  

                   
// x is true after the initial split
                   
if (x==true) {
                       
String roiN = rois.get(r).getName();
                       
System.out.println("Split made: " + roiN);
                       
if (roiN != base && MultiFretIcy.PS.transformEnabled == true) {
                       
Transform(seqBundle.get(r), transfoFile, roiN);
                       
}
                   
}
                    seqBundle
.get(r).endUpdate();      
               
}
           
}
       
}

Apologies if it's a bit messy, please ask for any clarification needed.
Reply all
Reply to author
Forward
0 new messages