I am trying to read an ImageJ XY coordinates file (attached) using the code below but I get a strange output. Any idea what I did wrong?
clc;
clear;
close all;
imgMatrix = readmatrix("E:/fd1.txt");
imgMatrix(:,3) = []
x=imgMatrix(:,1);y=imgMatrix(:,2);
BW = poly2mask(x,y,ceil(max(y)) ,ceil(max(x)));
imshow(BW);
Original image:
Output image:
fd1.txt file: https://mega.nz/file/vE0SxDgb#rQuWCsH8H2fYvuzGTSMgjyMMdyZGfQYMhLJ3zdXcJB4
Thanks a lot


I must admit that I have no experience with MATLAB but let me explain a bit the format ImageJ uses, if you export values per "Analyze >> Tools >> Save XY Coordinates...".
If, like in the case in question, the background of an 8bit gray-value image is black (zero), I would first invert the image (important!) and set the background value in the "Save XY Coordinates"-dialog to zero, as well as check "Invert y coordinates off".
In the following I shall provide an ImageJ-macro that indirectly explains the structure of the data by reconstructing the image from the data that has to be saved with suffix ".tsv" not ".txt". Open this data file in ImageJ first and then run the macro:
HTH