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
1 次查看(过去 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179203/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179160/image.jpeg)
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.)
另请参阅
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 (한국어)