MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Draw partial white border line in an object in grayscale

Asked by Demons on 25 Jan 2013

Hi all. This could be easy to some (or probably most) but sadly not me.

Here's original image: http://www.imagesup.net/?di=1513591333332

White blob of above image (if that matter): http://www.imagesup.net/?di=1213591337642

And here's what the output image should be: http://www.imagesup.net/?di=1113591338872

Is that possible to add/draw that white line as per output image?

DE

## Products

No products are associated with this question.

Answer by Image Analyst on 26 Jan 2013

How did you draw the red line in the first place? Since you have that (or SHOULD have that), it will be easy to just scan the image writing a white dot at each location.

Demons on 28 Jan 2013

No outsource labour used or any sort. Just me. If you scroll back to previous texts, the primary objectives are to reduce as much time and effort as possible. If I run method you suggested above, I have to consistently focus on one image, in which as a result took longer time to process.

Say I've got 100 of such images, if I manually draw the red (or any colour if that matter) marker to divide the wanted and unwanted area, then stash them to MATLAB to do the magic, I'd think the processing time will be greatly reduced.

The idea is to segment the ROI and get the area (pixel value) of gray area (muscles), black (outer bone) and white (inner bone).

I must admit that my OP wasn't that clear and the requirement of white border line is totally from my beginner MATLAB brain. I just thought with that white border line I could then easily compute the ROIs above, especially the outer bone part (black pixel).

Image Analyst on 28 Jan 2013

Well I think you're wrong - you're doubling the amount of code. But this is how you do that

First draw the dividing line using imfreehand() or however you're doing it. Convert the image to true color. Take the coordinates and write the red path as a colored curve into the image. Now, instead of masking out that portion and being done with everything, save the image. You're doing all of this already. Now for the next step (which normally wouldn't be necessary).

Read in the color image. Take the red channel and the blue channel and find the red line by doing

```redPixels = redChannel == 255 & blueChannel == 0;
```

Now scan the image column by column using find to find the lowest row that is red

```[rows columns] = size(redPixels);
lowestRow = columns * ones(1, columns); % Array to hold lowest row.
for col = 1 : columns
lowRow = find(redPixels(:, col), 1, 'last')
if ~isempty(lowRow)
% There is some red in that column.  Save it.
lowestRow(col) = lowRow;
end
end
```

Now you have the location of the bottom of that wide red swath you drew. Essentially it will be the same as the path you drew with imfreehand() but a little lower since you drew in a thick red path. Now you can use poly2mask() to create a mask from those coordinates and mask it off using code I already gave you above.

Demons on 28 Jan 2013

Thanks IA. Your input, time and effort are much appreciated. I'll try to sort this out and will let you know should I stuck somewhere.

Answer by Thorsten on 25 Jan 2013
```help imfreehand
```

Demons on 25 Jan 2013

the limit for manual interaction from human supervision is only once and this has been fulfilled when the red marker as per original image was drawn.

any automated method you could think of?

Image Analyst on 25 Jan 2013

What!?!? What kind of requirement or constraint is that? Why do you say that? Do you want to solve the problem or not? Yes, there are ways but I want to hear about these crazy constraints first. There's clearly something you haven't shared with us for some reason, and we don't want to waste time only to have you tell us "I forgot to tell you, I'm not allowed to do that either."

Demons on 26 Jan 2013

That's it really. I have to deal with thousands of those images, further manual interaction will results the same time taken to segment the whole area manually hence why the limitation.

Excuse my ignorance as I'm a beginner matlab user and dont properly know the rules of thumb as to what's the best lines to ask