Hello,
I've managed to make it work with the code below. Trying to figure out now how to change the grayscale exactly below the line from 255 to 0.
clc;
clear all;
close all;
%Read and show original image
Im_in = imread('20170807_Test7_test_concatd_volume_CROPPEDnROT97_789x867x1001_0001.tif');
subplot(2,2,1);
imshow(Im_in);
title('1: original image');
% Get size of the original image
[szy, szx] = size(Im_in);
%Find point A (First column + Find first row to be black)
xa = 1;
ya = (find(Im_in(:,1)==0, 1, 'first'));
%Find point B (Last column + Find first row to be black);
xb = szx;
yb = find(Im_in(:,szx)==0, 1, 'first');
% Define x and z
x = 100;
z = 250;
%Define increased picture size
Im_out = uint8(255*ones(x+szy, x+szx+z));
%Put original image in new image and display
Im_out(x+1:end,x+1:x+szx) = Im_in;
subplot(2,2,2);
h_im = imshow(Im_out); %not sure why this is required, but code fails without this.
title('2: new expanded image');
%assigning the line to a handle for the line
hLine = imline(gca,[1 100],[1 120]);
%creating a binary mask for the line
BinarkMask = createMask(hLine,h_im);
% only displaying the binary mask for the line
subplot(2,2,3);
imshow(BinarkMask);
title('binary mask for the line');
% Burn line into image by setting it to 0 wherever the mask is true.
Im_out(BinarkMask) = 0;
subplot(2, 2, 4);
cla;
imshow(Im_out);
title('new image with line');