how to get the image after using impixel() ?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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...
채택된 답변
Image Analyst
2014년 12월 24일
0 개 추천
They already are in the image. You can't even use impixel() if you don't already have an image.
댓글 수: 7
Manoj Kumar
2014년 12월 24일

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
2014년 12월 24일
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
2014년 12월 24일
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
2015년 1월 26일
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...
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
2015년 1월 26일
thanks,
I have a small doubt like, when we click on two blobs, then how to find the distance between two blobs over here.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
