I have an image and its centroid and I plotted lines passing through the centroid. And I wonder if it would be possible to represent separately each of the parts that are on either side of the line to work with them separately. You can get to the representation of each of
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
dividing an image into two with the aid of a line
조회 수: 3 (최근 30일)
이전 댓글 표시
hello! I have not much experience with matlab and I have a question! I wonder if drawing a line on an image, the image can be divided into two parts from that line and represent each of them separately! thank you very much to all
채택된 답변
elena
2013년 4월 30일
댓글 수: 15
Image Analyst
2013년 4월 30일
How many lines? What angles are they at? Please upload a screenshot of your image with the line overlaid onto it to snag.gy. And please answer the questions I asked in my comment above.
elena
2013년 5월 1일
the image is melanoma, but it serves any image. I want to draw a line passing through the centroid and I'm spinning at different angles, so the angle is not important. Would be drawing a line on any image, the image can be split through that line. Are not any curved line. What is snag.gy? instead of dividing the image into two parts, I also used two different matrices store the data of each of the parties, but neither is how. Can you help me on this?
Image Analyst
2013년 5월 1일
편집: Image Analyst
2013년 5월 1일
An image has to be rectangular. What do you want to have in the space where your quadrilateral image is not present? Just black?
http://snag.gy is a web site where you can just paste your screenshot. Hit print screen, then go to snag.gy and type control-v. Then tell us the URL.
And you never answered my question above as to what it means "to plot" the image. Please answer.
elena
2013년 5월 2일
when I said I meant plot the image to draw or represent the area of the image that was on the side of the line. But now I would have to be able to save the data in a matrix. I mean, I have an image and a line running through it, well, I would like to save on two different data matrices that are on each side of the line, to be able to work well with them separately, not necessarily convert the other values to black. this is my image with a line (which could be any other) http://snag.gy/FyszT.jpg Now I would like to know how to save on two different matrices each of the areas separated by the line. I tried with a for loop but I only keep the last value, not how to save all settings. Do not know if I'm explaining it right. I appreciate your help.
Image Analyst
2013년 5월 2일
Then just scroll up. I didn't sent them to you - I posted them here. Extend your line to the edges of the image, figure out what the coordinates are, then blacken out above or below that, then use imcrop and imwrite for each half.
elena
2013년 5월 2일
I did not understand very well what I have to do. I try to work with the command imcrop, but the only thing I'm able to cut are rectangles, not how to do to crop an image regardless of which direction this the line. Another thing is that to use the command imcrop need not take the points that demarcate the cropped image manually, but I have to do everything programmatically. How I can do? thanks for your help
Image Analyst
2013년 5월 2일
An image must stay rectangular. But you can find the bounding box of your polygon. If you want to analyze within the polygon, then you have to get a binary image of it and use regionprops.
Have you gone through and understood my Image Segmentation Tutorial yet? http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
elena
2013년 5월 2일
I've been watching the demo code for segmentation of the image and I think more or less I understand everything. But I've tried to label the components of my image and I get only one, the whole melanoma, ignores the line to split. So I have not been very clear idea of how to do it. I'm sorry but it is very difficult for me.
Image Analyst
2013년 5월 2일
편집: Image Analyst
2013년 5월 2일
Maybe I'll have time later to help you if you upload the original image plus the binary mask that goes with it. No promises though. But what do you want to know about it? The intensity on each side of the line? The length of the line inside the lesion for each angle? Something else?
elena
2013년 5월 3일
I just want to divide it into two parts so to calculate the centroid of each, but I think I know how to do without having to divide them. I try to do, and if I can not resolve I will ask again. Thank you very much for your help.
Image Analyst
2013년 5월 3일
Why do you want the centroid on each side? Well, anyway, here is the code to do that. You will have to change the folder name (where you stored the image because it is not the same folder as where I stored in on my computer), and if you're starting from the original binary image, you can cut out the part where I read in the figure you uploaded and cropped it.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
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 a standard MATLAB gray scale demo image.
folder = 'C:\Users\Elena\Documents\Temporary';
baseFileName = 'FyszT.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Crop it
grayImage = imcrop(grayImage, [370, 156, 620, 428]);
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
title('Cropped Grayscale Image', 'FontSize', fontSize);
% Turn it into a binary image and do a closing to fillin the black line.
binaryImage = imclose(grayImage > 0, true(3));
subplot(2, 3, 3);
imshow(binaryImage, []);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Ask use to draw a line
promptMessage = sprintf('Locate the end points of the line on the upper right image.\nMove to the center of the line (until you get the quad arrows)\nand double click when done');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'Cancel')
return;
end
hLine = imline;
position = wait(hLine)
% Create a binary image ("mask") from the ROI object.
lineMask = hLine.createMask();
subplot(2, 3, 4);
imshow(lineMask, []);
axis on;
title('Line Mask', 'FontSize', fontSize);
% Burn the line into the image
binaryImage(lineMask) = false;
subplot(2, 3, 5);
imshow(binaryImage, []);
axis on;
title('Binary Object Split into 2 Parts', 'FontSize', fontSize);
labeledImage = bwlabel(binaryImage, 4); % Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(2, 3, 6);
imagesc(coloredLabels);
axis on;
caption = sprintf('Pseudo colored labels, from label2rgb(),\nwith centroids marked.');
title(caption, 'FontSize', fontSize);
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
hold on;
for blob = 1 : numberOfBlobs
thisCentroid = blobMeasurements(blob).Centroid
plot(thisCentroid(1), thisCentroid(2), 'w+');
end
elena
2013년 5월 4일
I've managed to do what I was looking for, but anyway I will consider the code you sent me. Thank you very much for all your help, I really appreciate it.
Elysi Cochin
2015년 5월 7일
편집: Elysi Cochin
2015년 5월 7일
what if, i have the (x1,y1) and (x2,y2) points... where to edit the code.... how to get the lineMask please do help sir...
Image Analyst
2015년 5월 7일
If you have a large binary blob and you want to burn a line into it, see my attached demo.
추가 답변 (1개)
Image Analyst
2013년 4월 29일
How do you want to handle it if the line starts and stops within the image? Do you want to extend it until it hits the edge of the image? And then take the bounding box of each quadrilateral and zero out parts on the "wrong" side of the line?
댓글 수: 6
elena
2013년 4월 30일
I would like to find a function by which after drawing a line with any angle in the picture, you could plot separately each part of the image that is divided by that line. would this be possible? I appreciate your help
Image Analyst
2013년 4월 30일
So you have two quadrilateral-shaped gray scale images. What does it mean to "plot" them? Some kind of line curve that represents what???
Image Analyst
2013년 5월 1일
편집: Image Analyst
2013년 5월 1일
Do you mean like this:
so that you save two rectangular images, each with a three to five-sided black region?
sameena pathan
2017년 3월 21일
Hello Sir, Kindly help me in resolving this issue. How to divide a segmented portion of an image into two halves with respect to the major axis of the image? Your Kindness is greatly appreciated
Image Analyst
2017년 4월 8일
What information do you have so far? Do you at least have the formula or endpoints of the line? Or do you not even have that? If not, then what do you need to do to get that? Do you need to develop the ENTIRE image segmentation algorithm right from the very start after you call imread()? (I hope not.)
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)