dylanmuir / readimagejroi Goto Github PK
View Code? Open in Web Editor NEWMatlab function to import ROIs from ImageJ
Home Page: http://dylan-muir.com/articles/read_ij_roi/
Matlab function to import ROIs from ImageJ
Home Page: http://dylan-muir.com/articles/read_ij_roi/
There are always more pixels included in PixelIdxList than the area of ROI measured by ImageJ.
Sample.zip
Hi Dylan
Thank you for your useful tools.
It seems ROIs2Regions.m have bugs around handling x-y coordinates.
I tried to visualize my ('freehand') ROI data with the code below.
But it shows "fragmented" ROIs.
cvsROI = ReadImageJROI('RoiSet.zip');
sRegions = ROIs2Regions(cvsROI , vnImageSize);
mnLabelMatrix = labelmatrix(sRegions);
imagesc(label2rgb(mnLabelMatrix));
I checked ROIs2Regions.m and found 2 points.
[1] x-y was wrongly swapped.
ROIs2Regions apply transpose ('
) to the mbThisMask
.
That will cause swapping of x and y dimension.
sRegions.PixelIdxList{nROIIndex} = find(mbThisMask');
So I think it should be removed.
sRegions.PixelIdxList{nROIIndex} = find(mbThisMask);
With this change, the ROI shape in mnLabelMatrix
looks correct.
[2] Unnecessary +1
Additional validation, I compared the result with the image manually output from ImageJ.
I applied "Fill" to background and ROI with two different colors.
For background: Edit > Fill
For ROI: ROI Manager > More > Fill
mnImageJBinary= imread('Sample_ImageJ_Binary.tif');
imshowpair(mnImageJBinary>0, mnLabelMatrix>0);
And found that there is a shift between 2 images.
I guess that the addition of "1" to mnCoordinates is not necessary.
mbThisMask = poly2mask(sThisROI.mnCoordinates(:, 1)+1, sThisROI.mnCoordinates(:, 2)+1, vnImageSize(1), vnImageSize(2));
So it should be like below.
mbThisMask = poly2mask(sThisROI.mnCoordinates(:, 1), sThisROI.mnCoordinates(:, 2), vnImageSize(1), vnImageSize(2));
With editing these 2 points, ROIs2Regions.m works well for "Freehand" ROI in my environment.
I did not check for other cases "rectangle", "oval", "polygon".
First of all, I want to know this is generally happening or caused by my environment or somehow my misunderstanding.
My environment for this issue is below.
Matlab: 2019a
ImageJ: 1.52v on Fiji
Best,
Gaku
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.