-3

I am writing a MATLAB code to implement a specific filter on a selected (from auto ROI) grayscale region of a forearm image which consists of veins. I also uploaded the forearm of a subject (after foreground has extracted).

Basically, I have NIR camera images of the forearm of different subjects with different orientations. I wrote the code that has extracted the foreground grayscale image of the arm, that gave me the white background with the forearm. I used Sobel edge to find edges. I also found the nonzero indices using the find function. I got the row and col indices. I need an idea on how to extract image inside (almost 10 pixels) of the edges detected on both sides of the forearm (black and white edged image-also uploaded).

Sobel-edge:

sobel-edge

Foreground image:

Foreground image

ROI image that I need to extract:

roi image that I need to extract

clear all
close all
clc

image= rgb2gray(imread('Subj1.jpg'));
image1=~im2bw(image,0.1);
image1=im2uint8(image1);
foreground=imadd(image1,image);
imshow(foreground);
edgesmooth=medfilt2(foreground);
sobeledge= edge(edgesmooth,'sobel');
sobeledge=im2uint8(sobeledge);
figure 

imshow(sobeledge);
[col,row]=find(sobeledge~=0);
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
  • 1
    You want us to make an entire project in an answer of SO? Maybe with a couple of month, if you hire 4 or 5 of us – Ander Biguri Mar 07 '18 at 14:07
  • It is unclear what you want to do. Extract 10 pixels inside seems to me like an `imdillate` on the black and white image. https://nl.mathworks.com/help/images/ref/imdilate.html – Gelliant Mar 07 '18 at 14:33
  • 1
    Why do people always use the Sobel edge detector? What is wrong with just thresholding this image to get the arm? – Cris Luengo Mar 07 '18 at 15:09
  • @CrisLuengo lmao – rayryeng Mar 07 '18 at 19:50
  • I don't even understand what you actually want to achieve – Piglet Mar 07 '18 at 22:44
  • @CrisLuengo. Your point is valid based on the way I asked this question. Actually, I used Sobel operator to get the sharp transition region (boundary) of the forearm and then based on the points/indices of those pixels (I mentioned I used 'find' to do so) I need to used control loop statement to get an image with 10 pixels inside of the actual image. I am uploading an image file, of the final result, There are ways to do it manually like using 'roipoly' function, but I need to do it automatically. Any ideas are appreciated. Thanks – Fakhrul islam Mar 08 '18 at 07:27
  • @AnderBiguri I am extracting a region of the forearm to avoid sharp transition of background and foreground. I apologize if I was not clear before. Can you help me. Thanks in advance. – Fakhrul islam Mar 08 '18 at 10:37
  • This is a much clearer and sensical question now. I have reversed my vote. Look for `imdilate`. You want to apply that to the mask of the forearm to extend it by a certain distance. Use a disk structuring element. If I have time today I'll write up a proper answer. – Cris Luengo Mar 08 '18 at 14:11

1 Answers1

0

Starting from the mask image that you make here:

image1=~im2bw(image,0.1);

but inverted, such that the mask is zero for the background and non-zero for the foreground:

image1 = im2bw(image,0.1);

you can use imdilate to expand it by a fixed distance:

se = strel('disk',20); % This will extend by 20/2=10 pixels
image2 = imdilate(image1,se);

image2 will be like image1, but expanded by 10 pixels in all directions.

imerode does the opposite, it shrinks regions.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120