0

so I'm processing a bunch of images at the one time, trying to display them all as figures with a series of plotted lines on each individual image as a result of the process. With some help I fixed the figure title issue, However the plotted lines are not appearing on my final figures, below is the code:

inputFolder = fullfile(pwd, 'BMPData');
filePattern = fullfile(inputFolder, '*.bmp');
%Get list of all Bmp Files in Folder
BmpFiles = dir(filePattern)

for i=1:length(BmpFiles)
    fname = BmpFiles(i).name;
    fullFileNameInput = fullfile(inputFolder,fname);
    A = imread(fullFileNameInput);

    %// Change
    AR=A(:,:,1);
    [rows, columns] = size(AR);
    y1 = 200;
    y2 = 315;
    row1 = AR(y1, :); % Extract this line of gray levels from the image.
    row2 = AR(y2, :);
    figure('name',fname),imshow(A), hold on; 
    plot([0, columns], [y1, y1], '.b'); 
    plot([0, columns], [y2, y2], '.m');
end

The reason I am doing this is because I want to mark 2 rows (200 and 315) on all my images and then do some statistical analysis on all the pixels in them rows for further processing techniques.

  • OK great. That does it for one image. Can we see more code? Where is `fname` being set? – rayryeng Mar 04 '15 at 19:26
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4684363/how-to-change-the-window-title-of-a-matlab-plotting-figure – Martin J.H. Mar 04 '15 at 19:31
  • @rayryeng Ive added in my function and for statement, please see above, thanks. –  Mar 04 '15 at 20:08
  • Um, you copy/pasted a version of my answer that was not meant as a drop-in replacement. You are bound to get horrible errors in the second last line. The line `fh(i) = figure, imshow(A)` looks like an error, too. I think the `,` should be a `;`. Is there a reason why you have these statements on the same line? – Martin J.H. Mar 04 '15 at 20:11
  • Yea my apologies Just trying to 100 things at the one time today, Final year uni is really taking its tole on me! i really appreciate the feedback though, thanks. –  Mar 04 '15 at 20:43

1 Answers1

0

The reason why you're getting columns undefined is due to variable scope. When you define columns in SegmentationNew, columns is only available within the lifetime of SegmentationNew and only visible within SegmentationNew. Once SegmentationNew completes, column is no longer defined.

I honestly can't make heads or tails of what SegmentationNew is doing, but from the looks of it, there is no good reason why you should call it. All you need from it is y1 and y2, which are defined as constants. columns you can determine from the columns of the image. I'm also going to borrow from the duplicate post that Martin J.H. has linked to make naming the figure window more elegant.

To add to this post, your original code was plotting just the points. If you want to plot the lines as well, you need to remove the . characters from your plotting string for each call to plot. Specifically, change .b and .m to b and m respectively.

As such, do this:

for i=1:length(BmpFiles)
    fname = BmpFiles(i).name;
    fullFileNameInput = fullfile(inputFolder,fname);
    A = imread(fullFileNameInput);

    %// Change
    columns = size(A,2);
    y1 = 200;
    y2 = 315;

    figure('name',fname); %// Change
    imshow(A); hold on;
    plot([0, columns], [y1, y1], 'b'); hold on; %// Change
    plot([0, columns], [y2, y2], 'm');
end
rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • The figure titles are fine now however the plotted lines aren't appearing on them –  Mar 04 '15 at 21:06
  • I'm not sure what it is exactly that you're trying to plot. That's why I said I didn't understand what `SegmentationNew` was. BTW, reading code in a comments block gets pretty ugly when it's more than a couple of lines. Suggest you add this edit to your post. – rayryeng Mar 04 '15 at 21:07
  • sorry Im new to this website, Ive made edits to the question and tried to explain better. –  Mar 04 '15 at 21:17
  • @SeánMcNeill - Do you want to plot a **line** or just points? Your plot syntax at the end (`'.b, '.m'`) only plots single points. If you want to draw lines, remove the `.` for each `plot` call.... so just `b` and `m`. – rayryeng Mar 04 '15 at 22:35