From: Nicky on
So I am doing various image analysis on an image and want to be able to plot onto the source image once I am done. I have no problem plotting onto a black and white version of the same image (I run some filters to decide whether to color each pixel 0 or 255). When I plot onto it I use the following code:

imshow(BW); %this is the black and white image matrix of the original image
hold on
center = [mean(B{index}(:,2)),mean(B{index}(:,1))]; %this is my way of finding the centroid of the data on the image
plot(center(1),center(2),'b+')
hold off

So this shows the BW image, and plots a blue cross on the centroid of the image. I want to change this so it plots the same cross, but onto the original image. In my mind I would use the same code and just change the first line to read imshow(original). But when I run this code it seems like plotting the cross does nothing. Why would this happen and how can I fix it? Thank you!
From: ImageAnalyst on
Seems to work fine for me. Copy, paste, and study my example code
below:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear all; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.

% Read in standard MATLAB demo image.
rgbImage = imread('peppers.png');
[rows columns numberOfColorBands] = size(rgbImage);
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original color Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% For demo purposes, just plot a cross at the center
% (rather than the centroid.)
xCenter = columns/2;
yCenter = rows/2;
hold on;
plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);

% Get grayscale version of image.
grayImage = rgb2gray(rgbImage);
subplot(2, 2, 2);
imshow(grayImage, []);
title('Gray Scale Image');
hold on;
plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);

% Binarize the image.
binaryImage = grayImage > 100;
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image');
hold on;
plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);

% Now go back to the original image and plot a circle.
subplot(2, 2, 1);
plot(xCenter, yCenter, 'bo', 'MarkerSize', 56);

From: Nicky on
After playing with your code I realized that the problem doesn't lie in the plotting, rather for some reason my centroid that I find from the BW image does not match up with the original image. For example the center coordinates of the original are [79.5, 84], but the coordinates of the centroid are [162, 110.4]. So that means for some reason the image resizes or moves somewhere along in my code. I'll look into that, thank you for your help

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <4d341358-a923-4d79-a441-a38f081f86ff(a)k15g2000vbd.googlegroups.com>...
> Seems to work fine for me. Copy, paste, and study my example code
> below:
>
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> clear all; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
>
> % Read in standard MATLAB demo image.
> rgbImage = imread('peppers.png');
> [rows columns numberOfColorBands] = size(rgbImage);
> subplot(2, 2, 1);
> imshow(rgbImage, []);
> title('Original color Image');
> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
>
> % For demo purposes, just plot a cross at the center
> % (rather than the centroid.)
> xCenter = columns/2;
> yCenter = rows/2;
> hold on;
> plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);
>
> % Get grayscale version of image.
> grayImage = rgb2gray(rgbImage);
> subplot(2, 2, 2);
> imshow(grayImage, []);
> title('Gray Scale Image');
> hold on;
> plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);
>
> % Binarize the image.
> binaryImage = grayImage > 100;
> subplot(2, 2, 3);
> imshow(binaryImage, []);
> title('Binary Image');
> hold on;
> plot(xCenter, yCenter, 'r+', 'MarkerSize', 24);
>
> % Now go back to the original image and plot a circle.
> subplot(2, 2, 1);
> plot(xCenter, yCenter, 'bo', 'MarkerSize', 56);
From: ImageAnalyst on
Good luck with that. Another watchout is that MATLAB routines often
use the order (row,column) and (x,y) and you have to be really careful
about that because (row, column) is (y,x) not (x,y), and (x,y) is
(column, row) not (row, column). So sometimes the x and y of some
element you plotted or displayed will look swapped from where you
thought they'd be.