Azzera filtri
Azzera filtri

Plot Boxes then Plot them in the original photo ?

3 visualizzazioni (ultimi 30 giorni)
M
M il 24 Mag 2022
Modificato: DGM il 25 Mag 2022
I want to plot only the following boxes (5,6,7,8,9,10,12,13) from 19 box which their coordinates stored in the attached file "Boxes".
The color of the boxes should be as the following:
5,6 ==> Same color
7,8 ==> same color
9,10 ==> same color
12,13 ==> same color
I tried the following code to plot the specific mentioned boxes (5,6,7,8,9,10,12,13) , but the size of the boxes are too big compared with their original size(you can see their original size when you plot all the boxes):
%% Plot bboxes
p=cellfun(@polyshape, boxes);
plot(p); xlabel x; ylabel y
set(gca, 'YDir','reverse')
After ploting the boxes I want to plot them on the original photo(the attached one).??
  6 Commenti
M
M il 24 Mag 2022
@DGM, They are big when I plot the specific mentioned boxes only
DGM
DGM il 24 Mag 2022
Modificato: DGM il 24 Mag 2022
load boxes.mat
A = imread('Image.jpg');
imshow(A); hold on
boxes = num2cell(boxes,[1 2]);
p = cellfun(@polyshape, boxes);
p = p([5 6 7 8 9 10 12 13]);
colororder(repelem(lines(7),2,1))
plot(p);
xlabel x;
ylabel y
set(gca, 'YDir','reverse')

Accedi per commentare.

Risposta accettata

DGM
DGM il 24 Mag 2022
Modificato: DGM il 24 Mag 2022
The above comment should suffice if all you want is to plot with polyshape. If you actually want to modify the image without changing the image geometry or risking changing it outside of the specified boxes, then just modify the image directly instead of relying on the figure rendering as a cumbersome ad-hoc image compositor.
load boxes.mat
inpict = imread('Image.jpg');
imshow(inpict); hold on
alph = 0.4;
boxidx = [5 6 7 8 9 10 12 13];
boxcolors = repelem(lines,2,1);
for k = 1:numel(boxidx)
ROI = images.roi.Polygon(gca);
ROI.Position = boxes(:,:,boxidx(k));
mask = alph*createMask(ROI);
inpict = replacepixels(boxcolors(k,:),inpict,mask);
delete(ROI)
end
This uses MIMT replacepixels() to do the composition. You can do the same using basic tools, but it will be more verbose and you'll have to do all the class handling. This is an example of using basic tools to do composition using both logical and linear masks:
EDIT: something like this:
load boxes.mat
inpict = imread('Image.jpg');
imshow(inpict); hold on
alph = 0.4;
boxidx = [5 6 7 8 9 10 12 13];
boxcolors = repelem(lines,2,1);
inpict = im2double(inpict);
for k = 1:numel(boxidx)
ROI = images.roi.Polygon(gca);
ROI.Position = boxes(:,:,boxidx(k));
mask = alph*createMask(ROI);
inpict = permute(boxcolors(k,:),[1 3 2]).*mask + inpict.*(1-mask);
delete(ROI)
end
inpict = im2uint8(inpict);
  2 Commenti
M
M il 24 Mag 2022
Modificato: M il 24 Mag 2022
@DGM, Thanks . But I have two question please.
1- Can you please explain this line "colororder(repelem(lines(7),2,1))"
2- when I run your second code,I got the following error:
Error using images.roi.internal.mixin.CreateMask/validateInputs
Ambiguous syntax. Associated axes contains more than one image. Specify image handle as input argument to
resolve ambiguity.
Error in images.roi.internal.mixin.CreateMask/createMask
Error in Untitled3 (line 10)
mask = alph*createMask(ROI);
DGM
DGM il 25 Mag 2022
Modificato: DGM il 25 Mag 2022
1:
The axes 'colororder' property is an Mx3 colormap which is used by certain plotting tools as a default source for object colors. Its what defines the default line colors used by plot() when no colors are explicitly specified. In the case of your example, it's also used by plot() when plotting the polyshape objects.
For sake of consistency, I decided to use the same colors as before, just reordered to suit. The default value of the axes colororder property is lines(7). So the following
colororder(repelem(lines(7),2,1))
takes lines(7) (a 7x3 colormap) and duplicates each row to form a 14x3 colormap. This modified colormap is assigned to the axes colororder property by using the colororder() function.
The result is then that as each polyshape is plotted, the colors they are given get drawn from a list of duplicates. So the first and second shapes have the same color, and so on.
2:
You must have something else plotted in the same axes simultaneously, though it might not be intentional (or visible). If you had other things being displayed prior with 'hold on', that would be one cause, or if you modified the example code I gave in particular ways, it might also cause it. There can only be one image object in the axes when using the ROI tools. If there is a bunch of preceding code that had been plotting stuff in the axes, it would probably be a good idea to clear the axes/figure prior to starting this routine.
clf % clear the figure and child axes
% then do everything
Otherwise, you might want to show how exactly you're implementing the process.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by