Borrar filtros
Borrar filtros

Add a defined line (between two calculated points) to an image and make it a part of the image

5 visualizaciones (últimos 30 días)
Hello,
I have a binary image, to which I want to add a line between two points A [x1,y1] and B [x2,y2] (these points are extracted from the image using a code). I want to add this line to the image (alter the pixels of the along the line) and convert all the pixels below the line (equivalent to shading under the plot) to black.
Please note that the line to be added between the two defined points will be drawn in the white area of the binary image, therefore the line will be distinguishable. I have attached the image for your reference.
I used the following code, but it didn't work -
Im_in = imread('20170807_Test7_test_concatd_volume_CROPPEDnROT97_789x867x1001_0001.tif'); %input file
[szy, szx] = size(Im_in); % Get size of the original image
x = 100; %Define x for extending the image
z = 250; %Define z for extending the image
Im_out = uint8(255*ones(x+szy, x+szx+z)); %Define new image with increased size
singlelineimage = false(size(Im_out)); %Defining mask image for the to-be-added line
Im_out(x+1:end,x+1:x+szx) = Im_in; %Put original image in Im_out
hLine = line([1 60],[1 50]); %example line between [1,1] and [50,60]
singlelineimage = hLine.createMask();
Im_out(singlelineimage) = 0; %burn line into image by setting it to 0 or black where mask is true
imshow(Im_out);
Looking forward to your suggestions.
Thank you.
Somsubhro
  5 comentarios
Guillaume
Guillaume el 15 de Ag. de 2017
Editada: Guillaume el 15 de Ag. de 2017
The problem is not really (x,y) vs (y,x) (he/she got that right in the size query). It's the reusing of x in both dimensions. We even have x+z which I find very confusing because I think of z as the third dimension. I think it's just bad variable names.
Image Analyst
Image Analyst el 15 de Ag. de 2017
Yes, a better name for "x" would have been "margin" or "padding" or something else to indicate it was the amount the image would be enlarged.
Also, you should never use size like
[szy, szx] = size(Im_in); % Get size of the original image
unless you are 100% sure it's a gray scale image. It's much safer to always use
[rows, columns, numberOfColorChannels] = size(Im_in)
This will always give the correct number of columns for either gray scale or color images, while if you leave out numberOfColorChannels then columns will really be columns*numberOfColorChannels if it's a color image - not what you want. See Steve's blog http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by