Use of Define Grid


#1

Hi,

EDIT: Version - Vista x64 (7552) on Windows 7 x64 RC.

I’m planning to use Cellprofiler as an image analysis tool for my engineering thesis. Currently I’m using it with existing photographic data from previous trials conducted with a 2D Block Model. The aim of the project is to better understand the mechanics of material swell in block cave mining.

Essentially the model is packed or ‘loaded’ with a given material (in this case wooden blocks, however gravel etc. may be used in future) which is then withdrawn at the base of the model and collapse that results is logged with a series of photographs (1 photo each time a block is withdrawn). At this point some pictures will probably tell a thousand words:

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_a.jpg

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_b.jpg

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_c.jpg

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_d.jpg

The aim is to use Cellprofiler to identify the voids and then measure/output a couple of things:

  1. The area in each image that contains no blocks. (DONE, using the MeasureImageAreaOccupied module).

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_a_CroppedGray.png
http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_a_StainedCropped.png

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_b_CroppedGray.png
http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_b_StainedCropped.png

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_c_CroppedGray.png
http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_c_StainedCropped.png

http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_d_CroppedGray.png
http://i374.photobucket.com/albums/oo181/XDF_Mad/CellProfiler/th_d_StainedCropped.png

  1. Define a grid over the image, and do the same as in ‘1.’ but for each cell within the grid.

I’m struggling with this second goal, is it possible to use the DefineGrid function in this manner? Essentially I’d like to make it so that the MeasureImageAreaOccupied module runs within each cell of the grid, for every image in the series? I’ve attached the (very basic) pipeline that I’m using to measure the overall void area. I’ve tried adapting this to use the DefineGrid function but either I’m doing something wrong when setting it up or else or it can’t be used in the manner I would like…
DefaultOUT__1.mat (213 KB)


#2

Hi,

You can use DefineGrid in a couple of different ways:

  • If you have previously identified the cells, using a identification module, this can be used to create the rectangular grid using the Automatic setting. For identification, the blocks in the rectangular image would need to be clear enough so that they can be segmented, or alternately, load in a template image that has the blocks pre-segmented. Then in DefineGrid you would specify the # of cells across in width and height to span the grid.

  • If you haven’t or can’t previously identify the cells, you would define the grid using the Manual setting, and then by using Coordinates (instead of Mouse). You would then specify the location of the top-leftmost point, and the pixel distance between cells in width and height.

Afterward, you would use the IdentifyObjectsInGrid to create the individual rectangular cell elements that be would be used to measure the per-cell quantities. You can then use MeasureObjectIntensity applied to the binary image (Integrated intensity of an object over of a binary image is a simple surrogate for the area occupied). But I see the main hurdle as choosing which way to define your grid above.

Hope this helps!
-Mark


#3

Thank you Mark, I’ll see what I can do with that, it might be the IdentifyObjectsInGrid module that I’ve been using incorrectly.

Cheers,

Kris


#4

Hi,

Okay I think I have set up the DefineGrid and IdentifyObjectsInGrid modules correctly, however I’m receiving the following error with the MeasureObjectIntensity module:
**
There was a problem running the analysis module MeasureObjectIntensity which is number 09. Error using ==> sparse
Repeated indices are not supported for sparse logical matrices.

Stack:
MeasureObjectIntensity in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\Modules\MeasureObjectIntensity.m (319)
AnalyzeImagesButton_Callback in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (10890)
gui_mainfcn in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (12633)
CellProfiler in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (57)**

Is this error caused by defining the grid in an incorrect fashion, maybe with to few or too many cells, or perhaps by identifying the cells in the grid incorrectly?
Or is it a software or script error?

EDIT:

Matlab’s site has this to say:

*Creating Logical Matrices with the sparse Function. Previously, when creating sparse logical matrices, the sparse function accumulated entries when it encountered repeated indices. For example,

* A = sparse([1 1 1], 1, logical([1 0 1])) 
  A = 
      (1,1) 2

In MATLAB 6.5, sparse now returns an error, because the only valid logical values are 0 and 1:

* A = sparse([1 1 1], 1, logical([1 0 1])) 
  ??? Error using ==> sparse 
  Repeated indices are not supported for sparse logical matrices.*

Unfortunately I don’t have Matlab available at the moment, nor a decent enough understanding of the scripting language to resolve the issue…


#5

I’ve been looking at using the MeasureObjectAreaShape module as well. For some reason though it will only run one cycle, before I recieve an error with the DefineGrid module:

**There was a problem running the analysis module DefineGrid which is number 06. Error using ==> image
Parent property values must be scalar!

Stack:
imagesc in C:\Program Files\MATLAB\MATLAB Compiler Runtime\v78\toolbox\matlab\specgraph\imagesc.m (21)
CPimagesc in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CPsubfunctions\CPimagesc.m (34)
DefineGrid in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\Modules\DefineGrid.m (482)
AnalyzeImagesButton_Callback in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (10890)
gui_mainfcn in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (12633)
CellProfiler in J:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7522\CellProfiler_mcr\CellProfiler\CellProfiler.m (57)
**

The way I have DefineGrid set up is to define the grid once only, so I’m not sure why I’m receiving this error on the second cycle.


#6

Can anyone shed any light on those errors?
Any help would be greatly appreciated!

I’ll try running the same pipeline and images on a 32 bit Windows XP machine, hopefully that will indicate if the problems are related to my OS (Win 7 RC).


#7

[quote=“Kris”]Okay I think I have set up the DefineGrid and IdentifyObjectsInGrid modules correctly, however I’m receiving the following error with the MeasureObjectIntensity module:

There was a problem running the analysis module MeasureObjectIntensity which is number 09. Error using ==> sparse
Repeated indices are not supported for sparse logical matrices.[/quote]

I believe this is a bug in the code where the module is expecting a double-precision matrix and not a binary one. Instead, try using the MeasureObjectArea module in its place (which is probably the answer I should have given you first).

Regards,
-Mark


#8

I just noticed that you hit on the idea to switch to this module on your own. My mistake.
-Mark


#9

Can you post your pipeline plus the some images, so we can try to replicate the problem?
Regards,
-Mark


#10

Hi,

I’ve attached a zip file with four sample images and the pipeline I’m trying to get working, ‘MeasureObjectIntensityPIPE’. In the ‘Cellprofiler Output’ folder is an example of how I have been cropping the images. When setting the threshold interactively, you should be fine to use the default setting with these sample images.

The size and location of the grid is basically arbitrary at this point in time, if you can help me get the pipeline working at all for a series of images, then that would be a good first step :smiley:
I envisage using a manual grid (say 10x10 or greater resolution) which covers the majority of the cropped image. The cropped images should look very similar to the ones in my first post.

I’ve played around with some other versions of these pipelines and it appears that part of the problem might lie in using the mouse to define the grid. When using MeasureObjectAreaShape instead of MeasureObjectIntensity, in what is otherwise exactly the same pipeline, it would appear that one full cycle is completed before it errors out on the second cycle as mentioned in one of my recent posts (this pipeline is called ‘MeasureObjectAreaShapePIPE’.
If you use this pipeline but specify everything with coordinates (i.e. crop by coords and define the grid by coords) then it appears that the pipeline works for all the sample images without error.
I then attempted to substitute the MeasureObjectIntensity module back into this ‘Coordinate’ version of the pipeline, but it errors in exactly the same fashion as ‘MeasureObjectIntensityPIPE’.

Let me know if you need any further details, or clarification. I’ll be from Thursday till Sunday this week, so unless you get back to me before Thursday, chances are I won’t be able to get back to you till Monday next week.

Thank you for your help so far, I appreciate it.

Regards,

Kris
CellProfiler Pipes & Samples.zip (1.03 MB)


#11

Hi,

Any success in replicating the problem?


#12

Hi Kris,

Yes, I saw the same behavior (error-ring on the second cycle) and I was able to track down the bug. Unfortunately if you’re using the compiled version, this isn’t going to be something that you can fix or work around (there’s a typo in CalculateImageAreaOccupied and it’s related to retrieving the interactively-set-threshold, so that’s why you get it on the second cycle). If you absolutely need this functionality, I can try to get CP re-compiled with the fixes on Vista for you (since I see you are using the compiled version, I assume you don’t have matlab). Once I fixed the bug, both pipelines ran fine on all four images.

-Kate


#13

Hi Kate,

I’m rather tight on time, I need to get my data analysis done over the next two weeks unfortunately.

"If you absolutely need this functionality, I can try to get CP re-compiled with the fixes on Vista for you…"
That would be greatly appreciated if you could that!

However, if the time frame proves to be unachievable, what would be involved in making the changes myself and compiling and running the program from the source code? (Assuming I can get Matlab no problems).


#14

EDIT: I think I’ve worked out how to do what I asked, but I’m getting an error with OverlayOutlines (please see below).


#15

Yep, still having problems with the OverlayOutlines module.
I’ve attached the pipeline, as far as I can tell it should work… (I’m now using other software to crop and grayscale the images to reduce the cycle time in cellprofiler).

I keep getting the following error, I’m not sure why its looking for a blank “” file, in the pipeline the module is being told to look for a previously loaded image file called ‘Colour’:

There was a problem running the analysis module OverlayOutlines which is number 04.
Image processing was canceled in the OverlayOutlines module because CellProfiler could not find the input image. **CellProfiler expected to find an image named “”, but that image has not been created by the pipeline. Please adjust your pipeline to produce the image “” prior to this OverlayOutlines module.
**
Stack:
CPretrieveimage in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CPsubfunctions\CPretrieveimage.m (59)
OverlayOutlines in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\Modules\OverlayOutlines.m (129)
AnalyzeImagesButton_Callback in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (11093)
gui_mainfcn in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (12849)
CellProfiler in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (57)
ShortPipelineTestPIPE.mat (1.73 KB)


#16

It’s actually running into a problem when it tries to find CellOutlines. Try clicking on that name in the settings again- sometimes the settings just get corrupted. If clicking the name ‘CellOutlines’ again doesn’t work, just delete the entire module and add it in again.


#17

Hi,

Yep that does seem to have worked (adding the overlay modules into the pipeline again). However…
It only worked for the first two. The third (and final) time that I want to overlay the grid (on a binary image) I keep getting the following error:

**There was a problem running the analysis module OverlayOutlines which is number 10.
Invalid class name.

Stack:
intmax in C:\Program Files\MATLAB\R2009a\toolbox\compiler\mcr\matlab\elmat\intmax.m (53)
OverlayOutlines in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\Modules\OverlayOutlines.m (140)
AnalyzeImagesButton_Callback in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (11093)
gui_mainfcn in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (12849)
CellProfiler in M:\Cell Profiler\Compiled CellProfiler Vista64 V1.0.7949\CellProfiler_mcr\CellProfiler\CellProfiler.m (57)
**

Now as far as I can tell its setup identically to the others (which are now working), but obviously something is different, is it because its a binary image produced by the MeasureImageAreaOccupied module? Any other ideas as to what’s causing that error?

Sorry to keep you so busy doing IT support for me, I really appreciate your patience :smile:
ShortPipelineTest3PIPE.mat (1.68 KB)


#18

Yes, that’s right; apparently, the input needs to be non-binary for it to work properly. This is a bug which we will correct for a future release.

As it is, I see that you want to overlay red outlines on the binary image. Even if you didn’t get the error, the outlines would come out white since the input is not a color image. I believe you can work around both these problems by using a GrayToColor module beforehand, with Stained used as the input for all three R, G, and B channels. This will convert it to a color image which will look the same as the original binary one. This result should then work with OverlayOutlines.

Regards,
-Mark


#19

Ah good thinking, that seems so obvious now that you mention it :blush: