"
Phi.Lo I tried indenting the code as you advised but couldnt find an option in the editor"
That's Phi.Lho (PhiLho if the forum wasn't stubborn, but well...).
The option is in Editor > Auto Format (Ctrl+T). You indent too much, it makes hard to read the code.
I don't know what is MRI (medical term apparently, so not important I suppose) nor BFS, so it is hard to answer.
We cannot read the code, we cannot run it, hard to give an advice.
Well, I can give one: code where there is lot of similar lines is "smelly", ie. it is in bad shape.
Instead of repeating code for each neighbor of a pixel (I suppose that's what you do, I hadn't made a deep analysis), use an array to define the neighbors and iterate on it.
Example:
- PVector[] neighbors = {
- new PVector(-1, -1),
- new PVector(-1, 0),
- new PVector(-1, 1),
- new PVector( 0, -1),
- new PVector( 0, 0), // Maybe exclude it
- new PVector( 0, 1),
- new PVector( 1, -1),
- new PVector( 1, 0),
- new PVector( 1, 1),
- };
I used PVector because it is convenient to store a tightly coupled pair of values, but you could have used two arrays of ints if you prefer.
Large, repetitive code is hard to read, to detect errors in it, to maintain. Make the language to work for you, not the paste key of your editor!