How to use bwlabel or regionprops with cellfun ?

Hi, I have an image divided into small blocks using mat2cell. Now i want to perform bwlabel on each block(cell). bwlabel doesn't accept cell as input. So how do i do it? I need to find particles in each of these blocks ! Thank you

 Risposta accettata

Image Analyst
Image Analyst il 11 Ago 2015
Is the image already a binary image? A block is a small image and bwlabel() will work on a small image. Why not use blockproc() instead? I've attached two examples.

7 Commenti

Thank you for the reply. My image is binary. I have particles randomly appearing on my frame. So i took an image, divided into n blocks for m x n size. Now, I want to locate particle on each of these blocks for all my images (1000). I couldnt use bwlabel as it doesnt work on cell. So any suggestions pls? Thank you
Are you going to use 4-connected or 8-connected? Do you want just the centroids or every pixel in each blob? Each block may have a different number of blobs so you'd probably need a cell for each block position so you'd have a cell array with one cell for every block position in the image - that's a lot of cells. Each cell would have the centroid(s) of blob(s) in the cell, and optionally the number or blobs, the pixel locations, or anything else you want to add. I think after that you'd have an intractable mess, but anyway, is that what you want?
Hi, Thank you for the reply again. Yes, I have a cell array with 1 cell for each block. Approximately I have 33x23 cells in the array. Each cell is a 50x50 px^2 area. Now, i could use centroid to find position of each blob. But , my problem is : I cannot use regionprops on cell array. The function 'cellfun' doesnt work with regionprops. I want to find number of particles in each of the 50 x 50 cell. Centroids for every cell is what i want. I will use lenght(centroid) to find number of particles in each cell. Thanks
Of course you can. Did you see my second blockproc() example? In the first call to blockproc() in that m-file, see how I have a custom function where I turn the data into a 3x3 array and then do something with it? You'd adapt it to use an 8x8 array (very simple to do) and then you call bwlabel() and regionprops() instead of sum() like I did.
Give it a try. I'm moving my son to the University today so I don't have much time today.
Thank you so much ! Will look into in. If i am stuck could you help me out later? Maybe tmrw? I'll post a comment here if i am stuck. Else, Thank you and have a beautiful day !
We don't have internet up there yet so it will be sporadic. I will come home in a day or two and go back and forth a bit (it's 90 minute drive away) over the next week or so. In the meantime, if you get stuck, attach any m-file and data or images that would be needed to run your script.
Did you ever get this solved?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by