image quadrant one by one and move to next quadrant
1 次查看(过去 30 天)
显示 更早的评论
Hello, I want to show mask one quadrant by one quadrant and take images. But the code is making on one quadrant and the two and three...Eventually all the quadrants are on. After comparing the intensities of the image, I want to move to that quadrant and divide it again by four, such as in images pdf attached. Can anyone please help me with this?
% function dimension = getquadrant(q1,q2,q3,q4)
clc
clear all
close all
%%load dmd
classname = 'alpV42x64';
tagname = classname;
pseudoDLL = logical(0);
protofile = 'alpV42x64proto.m';
protofunc = @alpV42x64proto;
arch = 'win64';
dllfile = 'C:\Users\ReddyLabAdmin\Documents\MATLAB\alp4395.dll';
alplib('delete')
alplib('set', 'tag', tagname, 'classname', classname, ...
'dllfile', dllfile, 'pseudoDLL', pseudoDLL, 'protofile', protofile, ...
'protofunc', protofunc, 'arch', arch)
myapi = alpload();
mydev = alpdevice(myapi);
mydev.alloc();
%define the size of dmd
i = 1024;
j = 768;
dmd = zeros(i,j,'uint8');
[rows, columns, numColorChannels] = size(dmd)
numblocks = 2;
topRows = round(linspace(1, rows+1, numblocks + 1))
leftColumns = round(linspace(1, columns+1, numblocks + 1))
%show mask and capture image
for row = 1 : length(topRows) - 1
row1 = topRows(row);
row2 = topRows(row + 1) - 1;
for col = 1 : length(leftColumns) - 1
col1 = leftColumns(col);
col2 = leftColumns(col + 1) - 1;
dmd(row1 : row2, col1 : col2, :) = 255;
mydev.put(dmd);
myimage1 = captureimage();
%imwrite(myimage1,'r_row%d%dcolumn%d%d.jpg,row1, row2, col1, col2');
mydev.stop();
end
end
% %q1
% dmd = zeros(i,j,'uint8');
% q1 = 1:j/2,1:i/2;
% dmd(q1) = 255;
% mydev.put(dmd);
% myimage1 = captureimage();
% imwrite(myimage1,'Q1.jpg');
% mydev.stop();
% %q2
% dmd = zeros(i,j,'uint8');
% q2 = j/2:j,1:i/2;
% dmd(q2) = 255;
% mydev.put(dmd);
% myimage2 = captureimage();
% imwrite(myimage2,'Q2.jpg');
% mydev.stop();
% %q3
% dmd = zeros(i,j,'uint8');
% q3 = 1:j/2,i/2:i;
% dmd(q3) = 255;
% mydev.put(dmd);
% myimage3 = captureimage();
% imwrite(myimage3,'Q3.jpg');
% mydev.stop();
% %q4
% dmd = zeros(i,j,'uint8');
% q4 = j/2:j,i/2:i;
% dmd(q4) = 255;
% mydev.put(dmd);
% myimage4 = captureimage();
% imwrite(myimage4,'Q4.jpg');
% mydev.stop();
maximumintensity = calculatemaximum(myimage1,myimage2,myimage3,myimage4);
% if maximumintensity == meanIntensityValue1
% dimension = size(q1);
% else if maximumintensity == meanIntensityValue2
% dimension = size(q2);
%
% else if maximumintensity == meanIntensityValue3
% dimension = size(q3);
%
% else maximumintensity == meanIntensityValue4
% dimension = size(q4);
% end
2 个评论
采纳的回答
DGM
2021-10-10
编辑:DGM
2021-10-10
This should be a start
s = [768 1024];
% generate three masks that can be transformed and combined
% to create the desired masks
m4 = false(s);
m4(1:s(1)/2,1:s(2)/2) = true;
squaresize = s/4;
xx = mod(0:(s(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(s(1)-1),squaresize(1)*2)<squaresize(1);
m16 = xx & yy';
squaresize = s/8;
xx = mod(0:(s(2)-1),squaresize(2)*2)<squaresize(2);
yy = mod(0:(s(1)-1),squaresize(1)*2)<squaresize(1);
m64 = xx & yy';
% just display them for sake clarifying the example
subplot(1,3,1)
imshow(m4)
subplot(1,3,2)
imshow(m16)
subplot(1,3,3)
imshow(m64)
This is an example of how this can be used to generate all the masks:
clf
for a = 1:4
thismask = xfmask(m4,a);
% do something with the mask ...
dothings(thismask);
end
for a = 1:4
tm4 = xfmask(m4,a);
for b = 1:4
thismask = tm4 & xfmask(m16,b);
% do something with the mask ...
dothings(thismask);
end
end
for a = 1:4
tm4 = xfmask(m4,a);
for b = 1:4
tm16 = xfmask(m16,b);
for c = 1:4
thismask = tm4 & tm16 & xfmask(m64,c);
% do something with the mask ...
dothings(thismask);
end
end
end
% placeholder task function
function dothings(m)
imshow(m)
pause(0.1)
end
% convenience function to flip masks
function y = xfmask(x,k)
switch k
case 1
y = x;
case 2
y = fliplr(x);
case 3
y = flipud(x);
case 4
y = rot90(x,2);
otherwise
error('k must be between 1 and 4')
end
end
This will just show the masks in sequence. Bear in mind that if the equipment controller is expecting a uint8-scaled image, you can just use im2uint8(thismask) to convert it.
I bet there's some elegant way of doing this, but this works.
10 个评论
DGM
2022-3-4
Oh. So the intensity peak within the mask. ... but is the rest of it doing what you needed?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!