how to get the image after using impixel() ?

hi,
I used impixel() to select the particular pixels in an image.
pixelValues = impixel();
My problem is in displaying the selected pixels in the form of a image.
Can any one help me.
Thanks...

 Réponse acceptée

Image Analyst
Image Analyst le 24 Déc 2014

0 votes

They already are in the image. You can't even use impixel() if you don't already have an image.

7 commentaires

Manoj Kumar
Manoj Kumar le 24 Déc 2014
I have an image like this and I select 5 pixels in it by using impixel().
My question is how to get only those selected 5 pixels as the output?
Image Analyst
Image Analyst le 24 Déc 2014
impixel() gives you the color of the pixel(s) you clicked on. Is that what you want? Or do you want to get an image of only the 5 blobs you clicked on?
Manoj Kumar
Manoj Kumar le 24 Déc 2014
I just want the image containing the 5 blobs that I clicked.
Use ismember(). Here's code. Be sure to change the filename in the code, and mark the answer as Accepted if it does what you want.
%---------------------------------------------------------------------
% Demo to illustrate simple blob detection, measurement, and filtering.
% Requires the Image Processing Toolbox (IPT) because it demonstates some functions
% supplied by that toolbox.
% If you have the IPT (you can check by typing ver on the command line), you should be able to
% run this demo code simply by copying and pasting this code into a new editor window,
% and then clicking the green "run" triangle on the toolbar.
% Running time = 7.5 seconds the first run and 2.5 seconds on subsequent runs.
% A similar Mathworks demo:
% http://www.mathworks.com/products/image/demos.html?file=/products/demos/shipping/images/ipexprops.html
% Code written and posted by ImageAnalyst, December 2014.
%---------------------------------------------------------------------------
% Startup code.
tic; % Start timer.
clc; % Clear command window.
clearvars; % Get rid of variables from prior run of this m-file.
disp('Running test.m...'); % Message sent to command window.
workspace; % Make sure the workspace panel with all the variables is showing.
imtool close all; % Close all imtool figures.
format longg;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in demo image:
baseFileName = 'iamge.jpg';
folder = 'C:\Users\manoj\Documents\Temporary';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% It doesn't exist in the that folder.
% Look on the search path.
if ~exist(baseFileName, 'file')
% It doesn't exist on the search path either.
% Alert user that we can't find the image.
warningMessage = sprintf('Error: the input image file\n%s\nwas not found.\nClick OK to exit the demo.', fullFileName);
uiwait(warndlg(warningMessage));
fprintf(1, 'Finished running BlobsDemo.m.\n');
return;
end
% Found it on the search path. Construct the file name.
fullFileName = baseFileName; % Note: don't prepend the folder.
end
% If we get here, we should have found the image file.
rgbImage = imread(fullFileName);
imshow(rgbImage);
axis on;
title('Original RGB Image', 'FontSize', fontSize);
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Force it to display RIGHT NOW (otherwise it might not display until it's all done, unless you've stopped at a breakpoint.)
drawnow;
promptMessage = sprintf('Click on 5 points?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
[x, y] = ginput(5)
figure;
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color image', 'FontSize', fontSize);
% Check to make sure that it is grayscale.
[rows, columns, numberOfColorBands] = size(rgbImage);
if numberOfColorBands > 1
% Take the blue channel because it has the highest contrast.
grayImage = rgbImage(:,:,3);
else
grayImage = rgbImage;
end
subplot(2, 2, 2);
imshow(grayImage);
axis on;
title('Blue Channel gray scale image', 'FontSize', fontSize);
% Threshold the image to binarize it
binaryImage = grayImage > 128;
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage);
axis on;
title('Binary image.', 'FontSize', fontSize);
% Label the image - do connected components analysis.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 4); % Label each blob so we can make measurements of it
% Find the label that they clicked on
for k = 1 : length(x)
row = round(y(k))
column = round(x(k))
labelNumber(k) = labeledImage(row, column)
end
outputImage = ismember(labeledImage, labelNumber);
subplot(2, 2, 4);
imshow(outputImage);
axis on;
title('Output image.', 'FontSize', fontSize);
elapsedTime = toc;
% Alert user that the demo is done and give them the option to save an image.
message = sprintf('Finished running demo.\n\nElapsed time = %.2f seconds.', elapsedTime);
msgbox(message);
Manoj Kumar
Manoj Kumar le 26 Jan 2015
But here when I click on the bob, it is not showing any mark on it. Due to which there may be a chance to click on the same bob again.
Can you please tell me how to make a mark on the selected bob?
Thanks...
Image Analyst
Image Analyst le 26 Jan 2015
If you're using ginput() to have the user click on a blob, then you'll have to get the distances of that point to the centroids of all other blobs. This will work as long as the blobs are about the same diameter, but not, for example, if you click on the outer edge of a huge blob that is closer to the center of a nearby small blob than it is to the center of the huge blob. Another way is to use that point to create a binary image with just the pixel set where the user clicked on. Then use imreconstruct() to extract just the blob they clicked in. However if they actually missed and clicked in the black space, it won't get anything. If you want the nearest blob even if they didn't click inside one, then you'll have to call regionprops and get the PixelIdxList of all the pixels in all blobs and then see which labeled pixel is closest.
It really depends on how you define closest and what you want to do if the user "misses" and clicks outside a blob.
Manoj Kumar
Manoj Kumar le 26 Jan 2015
thanks,
I have a small doubt like, when we click on two blobs, then how to find the distance between two blobs over here.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by