Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to save image with opened imfreehand line

Asked by Demons on 4 Feb 2013

Hi I've been trying to save a grayscale image with opened imfreehand line (in my case I set the line up to red colour), but to no avail.

I'd like the saved image exactly as what was seen after drawing the line.

Any helps are much appreciated.

Many regards DE

Here's an example: http://www.imagesup.net/?di=10135999640812

0 Comments

Demons

Tags

1 Answer

Answer by Image Analyst on 4 Feb 2013
Accepted answer

I thought I already gave you the answer in http://www.mathworks.com/matlabcentral/answers/59898#comment_125529 This looks like the same question. Why wasn't this a follow up to that posting? Why is it a brand new question? It looks the same to me.

5 Comments

Demons on 5 Feb 2013

Once I took the imfreehand coordinate, how do I write the red line as a colored curve into the image, and save the new image as true (rgb) image?

Image Analyst on 5 Feb 2013
rgbImage = cat(3, grayImage, grayImage, grayImage);
for k = 1:length(x)
  row = y(k);
  column = x(k);
  % Assign red, green, and blue values to this pixel.
  rgbImage(row, column, 1) = 255;
  rgbImage(row, column, 2) = 0;
  rgbImage(row, column, 3) = 0;
end
imwrite(rgbImage, fullFileName);
Demons on 5 Feb 2013

Thanks IA, as usual. Need to tweak it a little but your code helps a lot.

Now once saved, the idea is to remove the unwanted region below the red line.

I've managed to scan the image and remove the unwanted region. How do I convert the detected red line to black?

Here's my code (red line detection and remove anything below it):

%red line detection and remove unwanted region underneath the red pixel
im = imread(filename);
[m n c] = size(im);
for i=1:n
  for j=1:m
     if ((im(j,i,1)>=200)&& (im(j,i,2)<200))
          break;  
      else imnew(j,i,:) = im(j,i,:);
      end
  end
end
imshow(imnew);
Image Analyst

Contact us